[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 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 17 | #include "base/bind.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 20 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 22 | #include "base/logging.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 26 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 27 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 28 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 29 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 30 | #include "base/test/metrics/histogram_tester.h" |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 31 | #include "base/test/scoped_task_environment.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 32 | #include "base/test/simple_test_clock.h" |
| 33 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 34 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 35 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 36 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 37 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 38 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 39 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 40 | #include "net/base/load_timing_info.h" |
| 41 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 42 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 43 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 44 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 45 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 46 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 47 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 48 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 49 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 50 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 51 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 52 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 53 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 54 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 56 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 57 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 58 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 59 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 60 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 61 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 62 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 63 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 64 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 65 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 66 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 67 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 68 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 69 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 70 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 71 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 72 | #include "net/log/test_net_log_entry.h" |
| 73 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 74 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 75 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 76 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 77 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 78 | #include "net/proxy_resolution/proxy_resolver.h" |
| 79 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 80 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 81 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 82 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 83 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 84 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 85 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 86 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 87 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 88 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 89 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 90 | #include "net/spdy/spdy_session.h" |
| 91 | #include "net/spdy/spdy_session_pool.h" |
| 92 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 93 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 94 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 95 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 96 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 97 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 98 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 99 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 100 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 101 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 102 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 103 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 104 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 105 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 106 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 107 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 108 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 109 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 110 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 111 | #if defined(NTLM_PORTABLE) |
| 112 | #include "base/base64.h" |
| 113 | #include "net/ntlm/ntlm_test_data.h" |
| 114 | #endif |
| 115 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 116 | #if BUILDFLAG(ENABLE_REPORTING) |
| 117 | #include "net/network_error_logging/network_error_logging_service.h" |
| 118 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 119 | #include "net/reporting/reporting_cache.h" |
| 120 | #include "net/reporting/reporting_client.h" |
| 121 | #include "net/reporting/reporting_header_parser.h" |
| 122 | #include "net/reporting/reporting_service.h" |
| 123 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 124 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 125 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 126 | using net::test::IsError; |
| 127 | using net::test::IsOk; |
| 128 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 129 | using base::ASCIIToUTF16; |
| 130 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 131 | //----------------------------------------------------------------------------- |
| 132 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 133 | namespace net { |
| 134 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 135 | namespace { |
| 136 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 137 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 138 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 139 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 140 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 141 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 142 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 143 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 144 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 145 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 146 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 147 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 148 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 149 | const char kAlternativeServiceHttpHeader[] = |
| 150 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 151 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 152 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 153 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 154 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 155 | } |
| 156 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 157 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 158 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 159 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 162 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 163 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 164 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 165 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 166 | if (!params) |
| 167 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 168 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 169 | if (!params->GetList("headers", &header_list)) |
| 170 | return false; |
| 171 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 172 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 173 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 174 | return true; |
| 175 | } |
| 176 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 178 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 179 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 180 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 181 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 182 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 183 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 184 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 185 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 186 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 187 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 188 | |
| 189 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 190 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 191 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 192 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 193 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 198 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 199 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 200 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 201 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 202 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | |
| 204 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 205 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 206 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 208 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 209 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 210 | load_timing_info.send_start); |
| 211 | |
| 212 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 213 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 214 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 216 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 217 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 221 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 222 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 224 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 226 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | |
| 228 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 229 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 230 | load_timing_info.proxy_resolve_end); |
| 231 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 232 | load_timing_info.send_start); |
| 233 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 234 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 235 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 237 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 238 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 242 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 243 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 244 | int connect_timing_flags) { |
| 245 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 246 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 247 | |
| 248 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 249 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 250 | load_timing_info.proxy_resolve_end); |
| 251 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 252 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 253 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 254 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 255 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 256 | load_timing_info.send_start); |
| 257 | |
| 258 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 259 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 260 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 262 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 263 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 264 | } |
| 265 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 266 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 267 | // result to return. |
| 268 | class CapturingProxyResolver : public ProxyResolver { |
| 269 | public: |
| 270 | CapturingProxyResolver() |
| 271 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 272 | ~CapturingProxyResolver() override = default; |
| 273 | |
| 274 | int GetProxyForURL(const GURL& url, |
| 275 | ProxyInfo* results, |
| 276 | CompletionOnceCallback callback, |
| 277 | std::unique_ptr<Request>* request, |
| 278 | const NetLogWithSource& net_log) override { |
| 279 | results->UseProxyServer(proxy_server_); |
| 280 | resolved_.push_back(url); |
| 281 | return OK; |
| 282 | } |
| 283 | |
| 284 | // Sets whether the resolver should use direct connections, instead of a |
| 285 | // proxy. |
| 286 | void set_proxy_server(ProxyServer proxy_server) { |
| 287 | proxy_server_ = proxy_server; |
| 288 | } |
| 289 | |
| 290 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 291 | |
| 292 | private: |
| 293 | std::vector<GURL> resolved_; |
| 294 | |
| 295 | ProxyServer proxy_server_; |
| 296 | |
| 297 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 298 | }; |
| 299 | |
| 300 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 301 | public: |
| 302 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 303 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 304 | |
| 305 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 306 | std::unique_ptr<ProxyResolver>* resolver, |
| 307 | CompletionOnceCallback callback, |
| 308 | std::unique_ptr<Request>* request) override { |
| 309 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 310 | return OK; |
| 311 | } |
| 312 | |
| 313 | private: |
| 314 | ProxyResolver* resolver_; |
| 315 | }; |
| 316 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 317 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 318 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 319 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 320 | } |
| 321 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 322 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 323 | public: |
| 324 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 325 | |
| 326 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 327 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 328 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 329 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 330 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 331 | return ERR_PAC_SCRIPT_FAILED; |
| 332 | } |
| 333 | }; |
| 334 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 335 | class TestSSLConfigService : public SSLConfigService { |
| 336 | public: |
| 337 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 338 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 339 | |
| 340 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 341 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 342 | bool CanShareConnectionWithClientCerts( |
| 343 | const std::string& hostname) const override { |
| 344 | return false; |
| 345 | } |
| 346 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 347 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 348 | SSLConfig config_; |
| 349 | }; |
| 350 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 351 | } // namespace |
| 352 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 353 | class HttpNetworkTransactionTest : public PlatformTest, |
| 354 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 355 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 356 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 357 | // Important to restore the per-pool limit first, since the pool limit must |
| 358 | // always be greater than group limit, and the tests reduce both limits. |
| 359 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 360 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 361 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 362 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 363 | } |
| 364 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 365 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 366 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 367 | : WithScopedTaskEnvironment( |
| 368 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 369 | base::test::ScopedTaskEnvironment::NowSource:: |
| 370 | MAIN_THREAD_MOCK_TIME), |
| 371 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 372 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 373 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 374 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 375 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 376 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 377 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 378 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 379 | struct SimpleGetHelperResult { |
| 380 | int rv; |
| 381 | std::string status_line; |
| 382 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 383 | int64_t total_received_bytes; |
| 384 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 385 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 386 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 387 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 388 | }; |
| 389 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 390 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 391 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 392 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 393 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 394 | // before incrementing the counter does not return a null value. |
| 395 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 396 | } |
| 397 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 398 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 399 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 400 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 401 | // Empty the current queue. |
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 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 404 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 405 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 406 | } |
| 407 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 408 | void Check100ResponseTiming(bool use_spdy); |
| 409 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 410 | // Either |write_failure| specifies a write failure or |read_failure| |
| 411 | // specifies a read failure when using a reused socket. In either case, the |
| 412 | // failure should cause the network transaction to resend the request, and the |
| 413 | // other argument should be NULL. |
| 414 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 415 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 416 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 417 | // Either |write_failure| specifies a write failure or |read_failure| |
| 418 | // specifies a read failure when using a reused socket. In either case, the |
| 419 | // failure should cause the network transaction to resend the request, and the |
| 420 | // other argument should be NULL. |
| 421 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 422 | const MockRead* read_failure, |
| 423 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 424 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 425 | SimpleGetHelperResult SimpleGetHelperForData( |
| 426 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 427 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 428 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 429 | HttpRequestInfo request; |
| 430 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 431 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 432 | request.traffic_annotation = |
| 433 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 434 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 435 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 436 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 437 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 438 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 439 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 440 | for (auto* provider : providers) { |
| 441 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 442 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 444 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 445 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 446 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 447 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 449 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 450 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 451 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 452 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 453 | |
| 454 | // Even in the failure cases that use this function, connections are always |
| 455 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 456 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 457 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 458 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 459 | if (out.rv != OK) |
| 460 | return out; |
| 461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 462 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 463 | // Can't use ASSERT_* inside helper functions like this, so |
| 464 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 465 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 466 | out.rv = ERR_UNEXPECTED; |
| 467 | return out; |
| 468 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 469 | out.status_line = response->headers->GetStatusLine(); |
| 470 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 471 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 472 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 473 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 474 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 475 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 476 | EXPECT_EQ(got_endpoint, |
| 477 | out.remote_endpoint_after_start.address().size() > 0); |
| 478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 479 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 481 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 482 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 483 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 484 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 485 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 486 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 487 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 488 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 489 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 490 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 491 | std::string line; |
| 492 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 493 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 494 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 495 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 496 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 497 | std::string value; |
| 498 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 499 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 500 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 501 | EXPECT_EQ("keep-alive", value); |
| 502 | |
| 503 | std::string response_headers; |
| 504 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 505 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 506 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 508 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 509 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 510 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 512 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 513 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 514 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 515 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 516 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 517 | MockWrite data_writes[] = { |
| 518 | MockWrite("GET / HTTP/1.1\r\n" |
| 519 | "Host: www.example.org\r\n" |
| 520 | "Connection: keep-alive\r\n\r\n"), |
| 521 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 522 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 523 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 524 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 525 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 526 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 527 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 528 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 529 | } |
| 530 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 531 | void AddSSLSocketData() { |
| 532 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 533 | ssl_.ssl_info.cert = |
| 534 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 535 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 537 | } |
| 538 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 539 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 540 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 541 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 542 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 543 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 544 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 545 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 546 | // These clocks are defined here, even though they're only used in the |
| 547 | // Reporting tests below, since they need to be destroyed after |
| 548 | // |session_deps_|. |
| 549 | base::SimpleTestClock clock_; |
| 550 | base::SimpleTestTickClock tick_clock_; |
| 551 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 552 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 553 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 554 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 555 | |
| 556 | // Original socket limits. Some tests set these. Safest to always restore |
| 557 | // them once each test has been run. |
| 558 | int old_max_group_sockets_; |
| 559 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 560 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 561 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 562 | namespace { |
| 563 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 564 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 565 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 566 | BeforeHeadersSentHandler() |
| 567 | : observed_before_headers_sent_with_proxy_(false), |
| 568 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 569 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 570 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 571 | HttpRequestHeaders* request_headers) { |
| 572 | observed_before_headers_sent_ = true; |
| 573 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 574 | !proxy_info.is_quic()) { |
| 575 | return; |
| 576 | } |
| 577 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 578 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 579 | } |
| 580 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 581 | bool observed_before_headers_sent_with_proxy() const { |
| 582 | return observed_before_headers_sent_with_proxy_; |
| 583 | } |
| 584 | |
| 585 | bool observed_before_headers_sent() const { |
| 586 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | std::string observed_proxy_server_uri() const { |
| 590 | return observed_proxy_server_uri_; |
| 591 | } |
| 592 | |
| 593 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 594 | bool observed_before_headers_sent_with_proxy_; |
| 595 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 596 | std::string observed_proxy_server_uri_; |
| 597 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 598 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 599 | }; |
| 600 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 601 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 602 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 603 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 604 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 605 | const int sizeof_row = strlen(row); |
| 606 | const int num_rows = static_cast<int>( |
| 607 | ceil(static_cast<float>(size) / sizeof_row)); |
| 608 | const int sizeof_data = num_rows * sizeof_row; |
| 609 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 610 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 611 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 612 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 613 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 614 | } |
| 615 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 616 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 617 | uint64_t MockGetMSTime() { |
| 618 | // Tue, 23 May 2017 20:13:07 +0000 |
| 619 | return 131400439870000000; |
| 620 | } |
| 621 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 622 | // Alternative functions that eliminate randomness and dependency on the local |
| 623 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 624 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 625 | // This is set to 0xaa because the client challenge for testing in |
| 626 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 627 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 628 | } |
| 629 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 630 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 631 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 632 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 633 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 634 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 635 | template<typename ParentPool> |
| 636 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 637 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 638 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 639 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 640 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 641 | const std::string last_group_name_received() const { |
| 642 | return last_group_name_; |
| 643 | } |
| 644 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 645 | bool socket_requested() const { return socket_requested_; } |
| 646 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 647 | int RequestSocket(const std::string& group_name, |
| 648 | const void* socket_params, |
| 649 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 650 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 651 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 652 | ClientSocketHandle* handle, |
Bence Béky | 5a8662b | 2018-07-03 13:04:03 | [diff] [blame] | 653 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 654 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 655 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 656 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 657 | return ERR_IO_PENDING; |
| 658 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 659 | void CancelRequest(const std::string& group_name, |
| 660 | ClientSocketHandle* handle) override {} |
| 661 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 662 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 663 | int id) override {} |
| 664 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 665 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 666 | int IdleSocketCount() const override { return 0; } |
| 667 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 668 | return 0; |
| 669 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 670 | LoadState GetLoadState(const std::string& group_name, |
| 671 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 672 | return LOAD_STATE_IDLE; |
| 673 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 674 | |
| 675 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 676 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 677 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 678 | }; |
| 679 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 680 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 681 | CaptureGroupNameTransportSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 682 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 683 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 684 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 685 | HostResolver* host_resolver, |
| 686 | CertVerifier* /* cert_verifier */) |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 687 | : ParentPool(0, |
| 688 | 0, |
| 689 | NULL, |
| 690 | host_resolver, |
| 691 | NULL, |
| 692 | NULL, |
| 693 | NULL, |
| 694 | NULL, |
| 695 | NULL, |
Matt Menke | c94d97b | 2019-02-01 19:28:28 | [diff] [blame] | 696 | NULL, |
Matt Menke | 1751ba7 | 2019-02-09 02:23:46 | [diff] [blame] | 697 | NULL, |
Daniel McArdle | da3fa94 | 2019-02-15 16:41:21 | [diff] [blame^] | 698 | NULL, |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 699 | NULL, |
| 700 | NULL, |
Matt Menke | fa9574f | 2019-01-28 18:55:27 | [diff] [blame] | 701 | NULL, |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 702 | NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 703 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 704 | //----------------------------------------------------------------------------- |
| 705 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 706 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 707 | // configured for common cases. |
| 708 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 709 | if (!auth_challenge) |
| 710 | return false; |
| 711 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 712 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 713 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 714 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 715 | return true; |
| 716 | } |
| 717 | |
| 718 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 719 | if (!auth_challenge) |
| 720 | return false; |
| 721 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 722 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 723 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 724 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 725 | return true; |
| 726 | } |
| 727 | |
| 728 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 729 | if (!auth_challenge) |
| 730 | return false; |
| 731 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 732 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 733 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 734 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 735 | return true; |
| 736 | } |
| 737 | |
| 738 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 739 | if (!auth_challenge) |
| 740 | return false; |
| 741 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 742 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 743 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 744 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 745 | return true; |
| 746 | } |
| 747 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 748 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 749 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 750 | if (!auth_challenge) |
| 751 | return false; |
| 752 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 753 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 755 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 756 | return true; |
| 757 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 758 | |
| 759 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 760 | if (!auth_challenge) |
| 761 | return false; |
| 762 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 763 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 764 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 765 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 766 | return true; |
| 767 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 768 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 769 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 770 | } // namespace |
| 771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 772 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 775 | } |
| 776 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 777 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 778 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 779 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 780 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 781 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 782 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 783 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 784 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 785 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 786 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 787 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 788 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 789 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 790 | |
| 791 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 795 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 796 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 797 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 798 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 799 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 800 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 801 | EXPECT_THAT(out.rv, IsOk()); |
| 802 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 803 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 804 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 805 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | } |
| 807 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 808 | // Response with no status line, and a weird port. Should fail by default. |
| 809 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 810 | MockRead data_reads[] = { |
| 811 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 812 | }; |
| 813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 814 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 816 | |
| 817 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 818 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 819 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 820 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 821 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 822 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 823 | request.method = "GET"; |
| 824 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 825 | request.traffic_annotation = |
| 826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 827 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 828 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 829 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 830 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 831 | } |
| 832 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 833 | // Tests that request info can be destroyed after the headers phase is complete. |
| 834 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 835 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 836 | auto trans = |
| 837 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 838 | |
| 839 | MockRead data_reads[] = { |
| 840 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 841 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 842 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 843 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 845 | |
| 846 | TestCompletionCallback callback; |
| 847 | |
| 848 | { |
| 849 | auto request = std::make_unique<HttpRequestInfo>(); |
| 850 | request->method = "GET"; |
| 851 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 852 | request->traffic_annotation = |
| 853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 854 | |
| 855 | int rv = |
| 856 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 857 | |
| 858 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 859 | } // Let request info be destroyed. |
| 860 | |
| 861 | trans.reset(); |
| 862 | } |
| 863 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 864 | // Response with no status line, and a weird port. Option to allow weird ports |
| 865 | // enabled. |
| 866 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 867 | MockRead data_reads[] = { |
| 868 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 869 | }; |
| 870 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 871 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 872 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 873 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 875 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 876 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 877 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 878 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 879 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 880 | request.method = "GET"; |
| 881 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 882 | request.traffic_annotation = |
| 883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 884 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 885 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 886 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 887 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 888 | |
| 889 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 890 | ASSERT_TRUE(info->headers); |
| 891 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 892 | |
| 893 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 894 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 895 | } |
| 896 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 897 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 898 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 899 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 900 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 901 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 902 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 903 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 904 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 905 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 906 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 907 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 908 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 912 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 913 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 914 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 917 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 918 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 920 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 921 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 922 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 926 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 927 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 928 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 931 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 932 | EXPECT_THAT(out.rv, IsOk()); |
| 933 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 934 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 935 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 936 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 940 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 942 | MockRead("\n"), |
| 943 | MockRead("\n"), |
| 944 | MockRead("Q"), |
| 945 | MockRead("J"), |
| 946 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 948 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 949 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 950 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 951 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 952 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 953 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 954 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 958 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 959 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 960 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 961 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 962 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 963 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 964 | EXPECT_THAT(out.rv, IsOk()); |
| 965 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 966 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 967 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 968 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 969 | } |
| 970 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 971 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 972 | // persistent connection. The response should still terminate since a 204 |
| 973 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 974 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 975 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 976 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 977 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 978 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 980 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 981 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 982 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 983 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 984 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 985 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 986 | int64_t response_size = reads_size - strlen(junk); |
| 987 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 988 | } |
| 989 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 990 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 991 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 992 | std::string final_chunk = "0\r\n\r\n"; |
| 993 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 994 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 995 | MockRead data_reads[] = { |
| 996 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 997 | MockRead("5\r\nHello\r\n"), |
| 998 | MockRead("1\r\n"), |
| 999 | MockRead(" \r\n"), |
| 1000 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1001 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1002 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1003 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1004 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1005 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1006 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1007 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1008 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1009 | int64_t response_size = reads_size - extra_data.size(); |
| 1010 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1011 | } |
| 1012 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1013 | // Next tests deal with http://crbug.com/56344. |
| 1014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1015 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1016 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1017 | MockRead data_reads[] = { |
| 1018 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1019 | MockRead("Content-Length: 10\r\n"), |
| 1020 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1021 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1022 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1023 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1024 | } |
| 1025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1026 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1027 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1030 | MockRead("Content-Length: 5\r\n"), |
| 1031 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1032 | MockRead("Hello"), |
| 1033 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1034 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1035 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1036 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1037 | EXPECT_EQ("Hello", out.response_data); |
| 1038 | } |
| 1039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1040 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1041 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1042 | // More than 2 dupes. |
| 1043 | { |
| 1044 | MockRead data_reads[] = { |
| 1045 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1046 | MockRead("Content-Length: 5\r\n"), |
| 1047 | MockRead("Content-Length: 5\r\n"), |
| 1048 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1049 | MockRead("Hello"), |
| 1050 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1051 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1052 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1053 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1054 | EXPECT_EQ("Hello", out.response_data); |
| 1055 | } |
| 1056 | // HTTP/1.0 |
| 1057 | { |
| 1058 | MockRead data_reads[] = { |
| 1059 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1060 | MockRead("Content-Length: 5\r\n"), |
| 1061 | MockRead("Content-Length: 5\r\n"), |
| 1062 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1063 | MockRead("Hello"), |
| 1064 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1065 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1066 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1067 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1068 | EXPECT_EQ("Hello", out.response_data); |
| 1069 | } |
| 1070 | // 2 dupes and one mismatched. |
| 1071 | { |
| 1072 | MockRead data_reads[] = { |
| 1073 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1074 | MockRead("Content-Length: 10\r\n"), |
| 1075 | MockRead("Content-Length: 10\r\n"), |
| 1076 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1077 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1078 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1079 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1083 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1084 | MultipleContentLengthHeadersTransferEncoding) { |
| 1085 | MockRead data_reads[] = { |
| 1086 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1087 | MockRead("Content-Length: 666\r\n"), |
| 1088 | MockRead("Content-Length: 1337\r\n"), |
| 1089 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1090 | MockRead("5\r\nHello\r\n"), |
| 1091 | MockRead("1\r\n"), |
| 1092 | MockRead(" \r\n"), |
| 1093 | MockRead("5\r\nworld\r\n"), |
| 1094 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1095 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 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, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1099 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1100 | EXPECT_EQ("Hello world", out.response_data); |
| 1101 | } |
| 1102 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1103 | // Next tests deal with http://crbug.com/98895. |
| 1104 | |
| 1105 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1106 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1107 | MockRead data_reads[] = { |
| 1108 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1109 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1110 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1111 | MockRead("Hello"), |
| 1112 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1113 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1114 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1115 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1116 | EXPECT_EQ("Hello", out.response_data); |
| 1117 | } |
| 1118 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1119 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1120 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1121 | MockRead data_reads[] = { |
| 1122 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1123 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1124 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1125 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1126 | MockRead("Hello"), |
| 1127 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1128 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1129 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1130 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1131 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1135 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1136 | MockRead data_reads[] = { |
| 1137 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1138 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1139 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1140 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1141 | MockRead("Hello"), |
| 1142 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1143 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1144 | EXPECT_THAT(out.rv, |
| 1145 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1146 | } |
| 1147 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1148 | // Checks that two identical Location headers result in no error. |
| 1149 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1150 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | MockRead data_reads[] = { |
| 1152 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1153 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1154 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1155 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1156 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | }; |
| 1158 | |
| 1159 | HttpRequestInfo request; |
| 1160 | request.method = "GET"; |
| 1161 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1162 | request.traffic_annotation = |
| 1163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1164 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1165 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1166 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1168 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1169 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1171 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1172 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1173 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1176 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1178 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1179 | ASSERT_TRUE(response); |
| 1180 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1182 | std::string url; |
| 1183 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1184 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1185 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1186 | } |
| 1187 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1189 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | MockRead data_reads[] = { |
| 1191 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1192 | MockRead("Location: http://good.com/\r\n"), |
| 1193 | MockRead("Location: http://evil.com/\r\n"), |
| 1194 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1195 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1196 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1197 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1198 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | } |
| 1200 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1201 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1202 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1203 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1204 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1205 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1206 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1207 | request.traffic_annotation = |
| 1208 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1209 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1211 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1212 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1213 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1214 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1215 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1216 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1217 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1218 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1219 | "Host: www.example.org\r\n" |
| 1220 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1221 | }; |
| 1222 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1223 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1224 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1225 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1226 | // No response body because the test stops reading here. |
| 1227 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | }; |
| 1229 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1230 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1231 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1233 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1234 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1235 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1236 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | |
| 1238 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1239 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1241 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1242 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | |
| 1244 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1245 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1246 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1247 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1248 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1249 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1250 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | |
| 1252 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1253 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | bool has_server_header = response->headers->EnumerateHeader( |
| 1255 | &iter, "Server", &server_header); |
| 1256 | EXPECT_TRUE(has_server_header); |
| 1257 | EXPECT_EQ("Blah", server_header); |
| 1258 | |
| 1259 | // Reading should give EOF right away, since there is no message body |
| 1260 | // (despite non-zero content-length). |
| 1261 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1262 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1263 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1264 | EXPECT_EQ("", response_data); |
| 1265 | } |
| 1266 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1267 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1269 | |
| 1270 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1271 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1272 | MockRead("hello"), |
| 1273 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1274 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1275 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1276 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1277 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1279 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1280 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1281 | "hello", "world" |
| 1282 | }; |
| 1283 | |
| 1284 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1285 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1286 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1287 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1288 | request.traffic_annotation = |
| 1289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1291 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1293 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1295 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | |
| 1298 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1299 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1301 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1302 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1304 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1305 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1306 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | |
| 1308 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1309 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1310 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1311 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1315 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1316 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1317 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1318 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1319 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1320 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1321 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | request.method = "POST"; |
| 1323 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1324 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1325 | request.traffic_annotation = |
| 1326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1328 | // Check the upload progress returned before initialization is correct. |
| 1329 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1330 | EXPECT_EQ(0u, progress.size()); |
| 1331 | EXPECT_EQ(0u, progress.position()); |
| 1332 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1335 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1337 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1338 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1339 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1340 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1342 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1345 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1347 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
| 1350 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1351 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1354 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1356 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1357 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
| 1359 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1360 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1361 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1362 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | } |
| 1364 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1365 | // This test is almost the same as Ignores100 above, but the response contains |
| 1366 | // 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] | 1367 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1368 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1369 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1370 | request.method = "GET"; |
| 1371 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1372 | request.traffic_annotation = |
| 1373 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1377 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1378 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1379 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1380 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1382 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1383 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1384 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1385 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1387 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1388 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1389 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1391 | |
| 1392 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1395 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1396 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1397 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1398 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1399 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1400 | |
| 1401 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1402 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1404 | EXPECT_EQ("hello world", response_data); |
| 1405 | } |
| 1406 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1407 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1408 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1409 | base::TimeDelta::FromMilliseconds(10); |
| 1410 | |
| 1411 | HttpRequestInfo request; |
| 1412 | request.method = "GET"; |
| 1413 | request.url = GURL("http://www.foo.com/"); |
| 1414 | request.traffic_annotation = |
| 1415 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1416 | |
| 1417 | std::vector<MockWrite> data_writes = { |
| 1418 | MockWrite(ASYNC, 0, |
| 1419 | "GET / HTTP/1.1\r\n" |
| 1420 | "Host: www.foo.com\r\n" |
| 1421 | "Connection: keep-alive\r\n\r\n"), |
| 1422 | }; |
| 1423 | |
| 1424 | std::vector<MockRead> data_reads = { |
| 1425 | // Write one byte of the status line, followed by a pause. |
| 1426 | MockRead(ASYNC, 1, "H"), |
| 1427 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1428 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1429 | MockRead(ASYNC, 4, "hello world"), |
| 1430 | MockRead(SYNCHRONOUS, OK, 5), |
| 1431 | }; |
| 1432 | |
| 1433 | SequencedSocketData data(data_reads, data_writes); |
| 1434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1435 | |
| 1436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1437 | |
| 1438 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1439 | |
| 1440 | TestCompletionCallback callback; |
| 1441 | |
| 1442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1444 | |
| 1445 | data.RunUntilPaused(); |
| 1446 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1447 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1448 | data.Resume(); |
| 1449 | |
| 1450 | rv = callback.WaitForResult(); |
| 1451 | EXPECT_THAT(rv, IsOk()); |
| 1452 | |
| 1453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1454 | ASSERT_TRUE(response); |
| 1455 | |
| 1456 | EXPECT_TRUE(response->headers); |
| 1457 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1458 | |
| 1459 | LoadTimingInfo load_timing_info; |
| 1460 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1461 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1462 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1463 | // Ensure we didn't include the delay in the TTFB time. |
| 1464 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1465 | load_timing_info.connect_timing.connect_end); |
| 1466 | // Ensure that the mock clock advanced at all. |
| 1467 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1468 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1469 | |
| 1470 | std::string response_data; |
| 1471 | rv = ReadTransaction(&trans, &response_data); |
| 1472 | EXPECT_THAT(rv, IsOk()); |
| 1473 | EXPECT_EQ("hello world", response_data); |
| 1474 | } |
| 1475 | |
| 1476 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1477 | // info uses the first response, even if 1XX/informational. |
| 1478 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1479 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1480 | base::TimeDelta::FromMilliseconds(10); |
| 1481 | |
| 1482 | HttpRequestInfo request; |
| 1483 | request.method = "GET"; |
| 1484 | request.url = GURL("https://www.foo.com/"); |
| 1485 | request.traffic_annotation = |
| 1486 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1487 | |
| 1488 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1490 | |
| 1491 | std::vector<MockWrite> data_writes; |
| 1492 | std::vector<MockRead> data_reads; |
| 1493 | |
| 1494 | spdy::SpdySerializedFrame spdy_req( |
| 1495 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1496 | |
| 1497 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1498 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1499 | spdy::SpdySerializedFrame spdy_resp1( |
| 1500 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1501 | spdy::SpdySerializedFrame spdy_resp2( |
| 1502 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1503 | spdy::SpdySerializedFrame spdy_data( |
| 1504 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1505 | |
| 1506 | if (use_spdy) { |
| 1507 | ssl.next_proto = kProtoHTTP2; |
| 1508 | |
| 1509 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1510 | |
| 1511 | data_reads = { |
| 1512 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1513 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1514 | MockRead(SYNCHRONOUS, OK, 5), |
| 1515 | }; |
| 1516 | } else { |
| 1517 | data_writes = { |
| 1518 | MockWrite(ASYNC, 0, |
| 1519 | "GET / HTTP/1.1\r\n" |
| 1520 | "Host: www.foo.com\r\n" |
| 1521 | "Connection: keep-alive\r\n\r\n"), |
| 1522 | }; |
| 1523 | |
| 1524 | data_reads = { |
| 1525 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1526 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1527 | |
| 1528 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1529 | MockRead(ASYNC, 4, "hello world"), |
| 1530 | MockRead(SYNCHRONOUS, OK, 5), |
| 1531 | }; |
| 1532 | } |
| 1533 | |
| 1534 | SequencedSocketData data(data_reads, data_writes); |
| 1535 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1536 | |
| 1537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1538 | |
| 1539 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1540 | |
| 1541 | TestCompletionCallback callback; |
| 1542 | |
| 1543 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1545 | |
| 1546 | data.RunUntilPaused(); |
| 1547 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1548 | // the delay before parsing the 200 response. |
| 1549 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1550 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1551 | data.Resume(); |
| 1552 | |
| 1553 | rv = callback.WaitForResult(); |
| 1554 | EXPECT_THAT(rv, IsOk()); |
| 1555 | |
| 1556 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1557 | ASSERT_TRUE(response); |
| 1558 | |
| 1559 | LoadTimingInfo load_timing_info; |
| 1560 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1561 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1562 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1563 | // Ensure we didn't include the delay in the TTFB time. |
| 1564 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1565 | load_timing_info.connect_timing.connect_end); |
| 1566 | // Ensure that the mock clock advanced at all. |
| 1567 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1568 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1569 | |
| 1570 | std::string response_data; |
| 1571 | rv = ReadTransaction(&trans, &response_data); |
| 1572 | EXPECT_THAT(rv, IsOk()); |
| 1573 | EXPECT_EQ("hello world", response_data); |
| 1574 | } |
| 1575 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1576 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1577 | Check100ResponseTiming(false /* use_spdy */); |
| 1578 | } |
| 1579 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1580 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1581 | Check100ResponseTiming(true /* use_spdy */); |
| 1582 | } |
| 1583 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1584 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1585 | HttpRequestInfo request; |
| 1586 | request.method = "POST"; |
| 1587 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1588 | request.traffic_annotation = |
| 1589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1590 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1593 | |
| 1594 | MockRead data_reads[] = { |
| 1595 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1596 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1597 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1598 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1599 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1600 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1601 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1602 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1603 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1605 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1606 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1607 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1608 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1609 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1610 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1611 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1612 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1613 | } |
| 1614 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1615 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1616 | HttpRequestInfo request; |
| 1617 | request.method = "POST"; |
| 1618 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1619 | request.traffic_annotation = |
| 1620 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1621 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1622 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1623 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1624 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1625 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1626 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1627 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1628 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1631 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1632 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1633 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1635 | |
| 1636 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1637 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1638 | } |
| 1639 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1640 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1641 | const MockWrite* write_failure, |
| 1642 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1643 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1644 | request.method = "GET"; |
| 1645 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1646 | request.traffic_annotation = |
| 1647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1648 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1649 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1650 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1652 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1653 | // Written data for successfully sending both requests. |
| 1654 | MockWrite data1_writes[] = { |
| 1655 | MockWrite("GET / HTTP/1.1\r\n" |
| 1656 | "Host: www.foo.com\r\n" |
| 1657 | "Connection: keep-alive\r\n\r\n"), |
| 1658 | MockWrite("GET / HTTP/1.1\r\n" |
| 1659 | "Host: www.foo.com\r\n" |
| 1660 | "Connection: keep-alive\r\n\r\n") |
| 1661 | }; |
| 1662 | |
| 1663 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1664 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1665 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1666 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1667 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1668 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1669 | |
| 1670 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1671 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1672 | data1_writes[1] = *write_failure; |
| 1673 | } else { |
| 1674 | ASSERT_TRUE(read_failure); |
| 1675 | data1_reads[2] = *read_failure; |
| 1676 | } |
| 1677 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1678 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1679 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1680 | |
| 1681 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1682 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1683 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1684 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1685 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1686 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1687 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1688 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1689 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1690 | "hello", "world" |
| 1691 | }; |
| 1692 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1693 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1694 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1695 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1701 | |
| 1702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1703 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1704 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1705 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1706 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1707 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1708 | if (i == 0) { |
| 1709 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1710 | } else { |
| 1711 | // The second request should be using a new socket. |
| 1712 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1713 | } |
| 1714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1715 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1716 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1717 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1718 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1719 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1720 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1721 | |
| 1722 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1723 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1724 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1725 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1726 | } |
| 1727 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1728 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1729 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1730 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1731 | const MockRead* read_failure, |
| 1732 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1733 | HttpRequestInfo request; |
| 1734 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1735 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1736 | request.traffic_annotation = |
| 1737 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1738 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1739 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1740 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1741 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1742 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1743 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1744 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1745 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1746 | ssl1.next_proto = kProtoHTTP2; |
| 1747 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1748 | } |
| 1749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1751 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1752 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1753 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1754 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1755 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1756 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1757 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1758 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1759 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1760 | // HTTP/1.1 versions of the request and response. |
| 1761 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1762 | "Host: www.foo.com\r\n" |
| 1763 | "Connection: keep-alive\r\n\r\n"; |
| 1764 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1765 | const char kHttpData[] = "hello"; |
| 1766 | |
| 1767 | std::vector<MockRead> data1_reads; |
| 1768 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1769 | if (write_failure) { |
| 1770 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1771 | data1_writes.push_back(*write_failure); |
| 1772 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1773 | } else { |
| 1774 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1775 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1776 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1777 | } else { |
| 1778 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1779 | } |
| 1780 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1781 | } |
| 1782 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1783 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1784 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1785 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1786 | std::vector<MockRead> data2_reads; |
| 1787 | std::vector<MockWrite> data2_writes; |
| 1788 | |
| 1789 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1790 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1791 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1792 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1793 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1794 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1795 | } else { |
| 1796 | data2_writes.push_back( |
| 1797 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1798 | |
| 1799 | data2_reads.push_back( |
| 1800 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1801 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1802 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1803 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1804 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1805 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1806 | |
| 1807 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1808 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1809 | // Wait for the preconnect to complete. |
| 1810 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1811 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1812 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1813 | |
| 1814 | // Make the request. |
| 1815 | TestCompletionCallback callback; |
| 1816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1817 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1818 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1819 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1821 | |
| 1822 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1823 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1824 | |
| 1825 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1826 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1827 | TestLoadTimingNotReused( |
| 1828 | load_timing_info, |
| 1829 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1832 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1834 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1835 | if (response->was_fetched_via_spdy) { |
| 1836 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1837 | } else { |
| 1838 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1839 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1840 | |
| 1841 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1842 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1844 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1845 | } |
| 1846 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1847 | // Test that we do not retry indefinitely when a server sends an error like |
| 1848 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1849 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1850 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1851 | HttpRequestInfo request; |
| 1852 | request.method = "GET"; |
| 1853 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1854 | request.traffic_annotation = |
| 1855 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1856 | |
| 1857 | // Check whether we give up after the third try. |
| 1858 | |
| 1859 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1860 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1861 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1862 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1863 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1864 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1865 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1866 | |
| 1867 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1868 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1869 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1870 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1871 | |
| 1872 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1873 | AddSSLSocketData(); |
| 1874 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1875 | AddSSLSocketData(); |
| 1876 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1877 | AddSSLSocketData(); |
| 1878 | |
| 1879 | TestCompletionCallback callback; |
| 1880 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1881 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1882 | |
| 1883 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1885 | |
| 1886 | rv = callback.WaitForResult(); |
| 1887 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1888 | } |
| 1889 | |
| 1890 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1891 | HttpRequestInfo request; |
| 1892 | request.method = "GET"; |
| 1893 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1894 | request.traffic_annotation = |
| 1895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1896 | |
| 1897 | // Check whether we try atleast thrice before giving up. |
| 1898 | |
| 1899 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1900 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1901 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1902 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1903 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1904 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1905 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1906 | |
| 1907 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1908 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1909 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1910 | spdy::SpdySerializedFrame spdy_data( |
| 1911 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1912 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1913 | CreateMockRead(spdy_data, 2)}; |
| 1914 | |
| 1915 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1916 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1917 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1918 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1919 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1920 | |
| 1921 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1922 | AddSSLSocketData(); |
| 1923 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1924 | AddSSLSocketData(); |
| 1925 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1926 | AddSSLSocketData(); |
| 1927 | |
| 1928 | TestCompletionCallback callback; |
| 1929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1930 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1931 | |
| 1932 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1934 | |
| 1935 | rv = callback.WaitForResult(); |
| 1936 | EXPECT_THAT(rv, IsOk()); |
| 1937 | } |
| 1938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1939 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1940 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1941 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1942 | } |
| 1943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1944 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1945 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1946 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1947 | } |
| 1948 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1949 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1950 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1951 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1952 | } |
| 1953 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1954 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1955 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1956 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1957 | MockRead read_failure(SYNCHRONOUS, |
| 1958 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1959 | "Connection: Keep-Alive\r\n" |
| 1960 | "Content-Length: 6\r\n\r\n" |
| 1961 | "Pickle"); |
| 1962 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1963 | } |
| 1964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1965 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1966 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1967 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1968 | } |
| 1969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1970 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1971 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1972 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1973 | } |
| 1974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1975 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1976 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1977 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1978 | } |
| 1979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1980 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1981 | MockRead read_failure(ASYNC, OK); // EOF |
| 1982 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1983 | } |
| 1984 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1985 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1986 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1987 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1988 | MockRead read_failure(SYNCHRONOUS, |
| 1989 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1990 | "Connection: Keep-Alive\r\n" |
| 1991 | "Content-Length: 6\r\n\r\n" |
| 1992 | "Pickle"); |
| 1993 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1994 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1995 | } |
| 1996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1997 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1998 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1999 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 2000 | } |
| 2001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2002 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2003 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 2004 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2005 | } |
| 2006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2007 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2008 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 2009 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2010 | } |
| 2011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2012 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2013 | MockRead read_failure(ASYNC, OK); // EOF |
| 2014 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2015 | } |
| 2016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2017 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2018 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2020 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2021 | request.traffic_annotation = |
| 2022 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2023 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2025 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2026 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2027 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2028 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2029 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2030 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2031 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2032 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2033 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2034 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2035 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2036 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2037 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2038 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2040 | |
| 2041 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2042 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2043 | |
| 2044 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2045 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2046 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | // What do various browsers do when the server closes a non-keepalive |
| 2050 | // connection without sending any response header or body? |
| 2051 | // |
| 2052 | // IE7: error page |
| 2053 | // Safari 3.1.2 (Windows): error page |
| 2054 | // Firefox 3.0.1: blank page |
| 2055 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2056 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2057 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2058 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2059 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2060 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2061 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2062 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2063 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2064 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2065 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2066 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2067 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2068 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2069 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2070 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2071 | // destructor in such situations. |
| 2072 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2073 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2074 | HttpRequestInfo request; |
| 2075 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2076 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2077 | request.traffic_annotation = |
| 2078 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2079 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2081 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2082 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2083 | |
| 2084 | MockRead data_reads[] = { |
| 2085 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2086 | MockRead("Connection: keep-alive\r\n"), |
| 2087 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2088 | MockRead("hello"), |
| 2089 | MockRead(SYNCHRONOUS, 0), |
| 2090 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2091 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2092 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2093 | |
| 2094 | TestCompletionCallback callback; |
| 2095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2096 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2098 | |
| 2099 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2101 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2102 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2103 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2104 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2105 | if (rv == ERR_IO_PENDING) |
| 2106 | rv = callback.WaitForResult(); |
| 2107 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2108 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2109 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2110 | |
| 2111 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2112 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2113 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2114 | } |
| 2115 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2116 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2117 | HttpRequestInfo request; |
| 2118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2119 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2120 | request.traffic_annotation = |
| 2121 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2122 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2124 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2125 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2126 | |
| 2127 | MockRead data_reads[] = { |
| 2128 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2129 | MockRead("Connection: keep-alive\r\n"), |
| 2130 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2131 | MockRead(SYNCHRONOUS, 0), |
| 2132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2133 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2135 | |
| 2136 | TestCompletionCallback callback; |
| 2137 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2138 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2140 | |
| 2141 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2142 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2143 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2144 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2145 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2146 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2147 | if (rv == ERR_IO_PENDING) |
| 2148 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2149 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2150 | |
| 2151 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2152 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2153 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2154 | } |
| 2155 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2156 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2157 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2158 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2159 | HttpRequestInfo request; |
| 2160 | request.method = "GET"; |
| 2161 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2162 | request.traffic_annotation = |
| 2163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2164 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2165 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2166 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2168 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2169 | const char* request_data = |
| 2170 | "GET / HTTP/1.1\r\n" |
| 2171 | "Host: www.foo.com\r\n" |
| 2172 | "Connection: keep-alive\r\n\r\n"; |
| 2173 | MockWrite data_writes[] = { |
| 2174 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2175 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2176 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2177 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2178 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2179 | }; |
| 2180 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2181 | // Note that because all these reads happen in the same |
| 2182 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2183 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2184 | MockRead data_reads[] = { |
| 2185 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2186 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2187 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2188 | MockRead(ASYNC, 7, |
| 2189 | "HTTP/1.1 302 Found\r\n" |
| 2190 | "Content-Length: 0\r\n\r\n"), |
| 2191 | MockRead(ASYNC, 9, |
| 2192 | "HTTP/1.1 302 Found\r\n" |
| 2193 | "Content-Length: 5\r\n\r\n" |
| 2194 | "hello"), |
| 2195 | MockRead(ASYNC, 11, |
| 2196 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2197 | "Content-Length: 0\r\n\r\n"), |
| 2198 | MockRead(ASYNC, 13, |
| 2199 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2200 | "Content-Length: 5\r\n\r\n" |
| 2201 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2202 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2203 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2204 | // the set_busy_before_sync_reads(true) call, while the |
| 2205 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2206 | // reuseable. See http://crbug.com/544255. |
| 2207 | MockRead(ASYNC, 15, |
| 2208 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2209 | "Content-Length: 5\r\n\r\n"), |
| 2210 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2211 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2212 | MockRead(ASYNC, 18, |
| 2213 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2214 | "Content-Length: 5\r\n\r\n" |
| 2215 | "he"), |
| 2216 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2217 | |
| 2218 | // The body of the final request is actually read. |
| 2219 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2220 | MockRead(ASYNC, 22, "hello"), |
| 2221 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2222 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2223 | data.set_busy_before_sync_reads(true); |
| 2224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2225 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2226 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2227 | std::string response_lines[kNumUnreadBodies]; |
| 2228 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2229 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2230 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2231 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2232 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2233 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2234 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2235 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2236 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2237 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2238 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2239 | LoadTimingInfo load_timing_info; |
| 2240 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2241 | if (i == 0) { |
| 2242 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2243 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2244 | } else { |
| 2245 | TestLoadTimingReused(load_timing_info); |
| 2246 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2247 | } |
| 2248 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2249 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2250 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2251 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2252 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2253 | response_lines[i] = response->headers->GetStatusLine(); |
| 2254 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2255 | // Delete the transaction without reading the response bodies. Then spin |
| 2256 | // the message loop, so the response bodies are drained. |
| 2257 | trans.reset(); |
| 2258 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2259 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2260 | |
| 2261 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2262 | "HTTP/1.1 204 No Content", |
| 2263 | "HTTP/1.1 205 Reset Content", |
| 2264 | "HTTP/1.1 304 Not Modified", |
| 2265 | "HTTP/1.1 302 Found", |
| 2266 | "HTTP/1.1 302 Found", |
| 2267 | "HTTP/1.1 301 Moved Permanently", |
| 2268 | "HTTP/1.1 301 Moved Permanently", |
| 2269 | "HTTP/1.1 200 Hunky-Dory", |
| 2270 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2271 | }; |
| 2272 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2273 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2274 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2275 | |
| 2276 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2277 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2279 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2281 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2282 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2283 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2284 | ASSERT_TRUE(response); |
| 2285 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2286 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2287 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2288 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2289 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2290 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2291 | } |
| 2292 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2293 | // Sockets that receive extra data after a response is complete should not be |
| 2294 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2295 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2296 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2297 | MockWrite data_writes1[] = { |
| 2298 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2299 | "Host: www.borked.com\r\n" |
| 2300 | "Connection: keep-alive\r\n\r\n"), |
| 2301 | }; |
| 2302 | |
| 2303 | MockRead data_reads1[] = { |
| 2304 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2305 | "Connection: keep-alive\r\n" |
| 2306 | "Content-Length: 22\r\n\r\n" |
| 2307 | "This server is borked."), |
| 2308 | }; |
| 2309 | |
| 2310 | MockWrite data_writes2[] = { |
| 2311 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2312 | "Host: www.borked.com\r\n" |
| 2313 | "Connection: keep-alive\r\n\r\n"), |
| 2314 | }; |
| 2315 | |
| 2316 | MockRead data_reads2[] = { |
| 2317 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2318 | "Content-Length: 3\r\n\r\n" |
| 2319 | "foo"), |
| 2320 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2321 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2323 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2324 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2325 | |
| 2326 | TestCompletionCallback callback; |
| 2327 | HttpRequestInfo request1; |
| 2328 | request1.method = "HEAD"; |
| 2329 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2330 | request1.traffic_annotation = |
| 2331 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2332 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2333 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2334 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2335 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2336 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2337 | |
| 2338 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2339 | ASSERT_TRUE(response1); |
| 2340 | ASSERT_TRUE(response1->headers); |
| 2341 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2342 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2343 | |
| 2344 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2345 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2346 | EXPECT_EQ("", response_data1); |
| 2347 | // Deleting the transaction attempts to release the socket back into the |
| 2348 | // socket pool. |
| 2349 | trans1.reset(); |
| 2350 | |
| 2351 | HttpRequestInfo request2; |
| 2352 | request2.method = "GET"; |
| 2353 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2354 | request2.traffic_annotation = |
| 2355 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2356 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2357 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2358 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2359 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2360 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2361 | |
| 2362 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2363 | ASSERT_TRUE(response2); |
| 2364 | ASSERT_TRUE(response2->headers); |
| 2365 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2366 | |
| 2367 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2368 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2369 | EXPECT_EQ("foo", response_data2); |
| 2370 | } |
| 2371 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2372 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2374 | MockWrite data_writes1[] = { |
| 2375 | MockWrite("GET / HTTP/1.1\r\n" |
| 2376 | "Host: www.borked.com\r\n" |
| 2377 | "Connection: keep-alive\r\n\r\n"), |
| 2378 | }; |
| 2379 | |
| 2380 | MockRead data_reads1[] = { |
| 2381 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2382 | "Connection: keep-alive\r\n" |
| 2383 | "Content-Length: 22\r\n\r\n" |
| 2384 | "This server is borked." |
| 2385 | "Bonus data!"), |
| 2386 | }; |
| 2387 | |
| 2388 | MockWrite data_writes2[] = { |
| 2389 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2390 | "Host: www.borked.com\r\n" |
| 2391 | "Connection: keep-alive\r\n\r\n"), |
| 2392 | }; |
| 2393 | |
| 2394 | MockRead data_reads2[] = { |
| 2395 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2396 | "Content-Length: 3\r\n\r\n" |
| 2397 | "foo"), |
| 2398 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2399 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2400 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2401 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2402 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2403 | |
| 2404 | TestCompletionCallback callback; |
| 2405 | HttpRequestInfo request1; |
| 2406 | request1.method = "GET"; |
| 2407 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2408 | request1.traffic_annotation = |
| 2409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2410 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2411 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2412 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2413 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2414 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2415 | |
| 2416 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2417 | ASSERT_TRUE(response1); |
| 2418 | ASSERT_TRUE(response1->headers); |
| 2419 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2420 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2421 | |
| 2422 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2423 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2424 | EXPECT_EQ("This server is borked.", response_data1); |
| 2425 | // Deleting the transaction attempts to release the socket back into the |
| 2426 | // socket pool. |
| 2427 | trans1.reset(); |
| 2428 | |
| 2429 | HttpRequestInfo request2; |
| 2430 | request2.method = "GET"; |
| 2431 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2432 | request2.traffic_annotation = |
| 2433 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2434 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2435 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2436 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2437 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2438 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2439 | |
| 2440 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2441 | ASSERT_TRUE(response2); |
| 2442 | ASSERT_TRUE(response2->headers); |
| 2443 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2444 | |
| 2445 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2446 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2447 | EXPECT_EQ("foo", response_data2); |
| 2448 | } |
| 2449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2450 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2452 | MockWrite data_writes1[] = { |
| 2453 | MockWrite("GET / HTTP/1.1\r\n" |
| 2454 | "Host: www.borked.com\r\n" |
| 2455 | "Connection: keep-alive\r\n\r\n"), |
| 2456 | }; |
| 2457 | |
| 2458 | MockRead data_reads1[] = { |
| 2459 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2460 | "Connection: keep-alive\r\n" |
| 2461 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2462 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2463 | MockRead("0\r\n\r\nBonus data!"), |
| 2464 | }; |
| 2465 | |
| 2466 | MockWrite data_writes2[] = { |
| 2467 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2468 | "Host: www.borked.com\r\n" |
| 2469 | "Connection: keep-alive\r\n\r\n"), |
| 2470 | }; |
| 2471 | |
| 2472 | MockRead data_reads2[] = { |
| 2473 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2474 | "Content-Length: 3\r\n\r\n" |
| 2475 | "foo"), |
| 2476 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2477 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2478 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2479 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2480 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2481 | |
| 2482 | TestCompletionCallback callback; |
| 2483 | HttpRequestInfo request1; |
| 2484 | request1.method = "GET"; |
| 2485 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2486 | request1.traffic_annotation = |
| 2487 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2488 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2489 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2490 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2491 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2492 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2493 | |
| 2494 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2495 | ASSERT_TRUE(response1); |
| 2496 | ASSERT_TRUE(response1->headers); |
| 2497 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2498 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2499 | |
| 2500 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2501 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2502 | EXPECT_EQ("This server is borked.", response_data1); |
| 2503 | // Deleting the transaction attempts to release the socket back into the |
| 2504 | // socket pool. |
| 2505 | trans1.reset(); |
| 2506 | |
| 2507 | HttpRequestInfo request2; |
| 2508 | request2.method = "GET"; |
| 2509 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2510 | request2.traffic_annotation = |
| 2511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2512 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2513 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2514 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2515 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2516 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2517 | |
| 2518 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2519 | ASSERT_TRUE(response2); |
| 2520 | ASSERT_TRUE(response2->headers); |
| 2521 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2522 | |
| 2523 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2524 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2525 | EXPECT_EQ("foo", response_data2); |
| 2526 | } |
| 2527 | |
| 2528 | // This is a little different from the others - it tests the case that the |
| 2529 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2530 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2531 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2532 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2534 | MockWrite data_writes1[] = { |
| 2535 | MockWrite("GET / HTTP/1.1\r\n" |
| 2536 | "Host: www.borked.com\r\n" |
| 2537 | "Connection: keep-alive\r\n\r\n"), |
| 2538 | }; |
| 2539 | |
| 2540 | MockRead data_reads1[] = { |
| 2541 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2542 | "Connection: keep-alive\r\n" |
| 2543 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2544 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2545 | MockRead("0\r\n\r\nBonus data!"), |
| 2546 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2547 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2548 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2549 | |
| 2550 | TestCompletionCallback callback; |
| 2551 | HttpRequestInfo request1; |
| 2552 | request1.method = "GET"; |
| 2553 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2554 | request1.traffic_annotation = |
| 2555 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2556 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2557 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2558 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2559 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2560 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2561 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2562 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2563 | ASSERT_TRUE(response1); |
| 2564 | ASSERT_TRUE(response1->headers); |
| 2565 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2566 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2567 | |
| 2568 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2569 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2570 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2571 | |
| 2572 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2573 | // socket can't be reused, rather than returning it to the socket pool. |
| 2574 | base::RunLoop().RunUntilIdle(); |
| 2575 | |
| 2576 | // There should be no idle sockets in the pool. |
| 2577 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2578 | } |
| 2579 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2580 | // Test the request-challenge-retry sequence for basic auth. |
| 2581 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2582 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2583 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2584 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2585 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2586 | request.traffic_annotation = |
| 2587 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2588 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2589 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2590 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2593 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2594 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2595 | MockWrite( |
| 2596 | "GET / HTTP/1.1\r\n" |
| 2597 | "Host: www.example.org\r\n" |
| 2598 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2599 | }; |
| 2600 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2601 | MockRead data_reads1[] = { |
| 2602 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2603 | // Give a couple authenticate options (only the middle one is actually |
| 2604 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2605 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2606 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2607 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2608 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2609 | // Large content-length -- won't matter, as connection will be reset. |
| 2610 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2611 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2612 | }; |
| 2613 | |
| 2614 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2615 | // be issuing -- the final header line contains the credentials. |
| 2616 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2617 | MockWrite( |
| 2618 | "GET / HTTP/1.1\r\n" |
| 2619 | "Host: www.example.org\r\n" |
| 2620 | "Connection: keep-alive\r\n" |
| 2621 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2622 | }; |
| 2623 | |
| 2624 | // Lastly, the server responds with the actual content. |
| 2625 | MockRead data_reads2[] = { |
| 2626 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2628 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2629 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2630 | }; |
| 2631 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2632 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2633 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2634 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2635 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2637 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2639 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2641 | |
| 2642 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2644 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2645 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2646 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2647 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2648 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2649 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2650 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2651 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2652 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2654 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2655 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2656 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2658 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2660 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2662 | |
| 2663 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2664 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2665 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2666 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2667 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2668 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2669 | // The load timing after restart should have a new socket ID, and times after |
| 2670 | // those of the first load timing. |
| 2671 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2672 | load_timing_info2.connect_timing.connect_start); |
| 2673 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2674 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2675 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2676 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2677 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2678 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2680 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2681 | ASSERT_TRUE(response); |
| 2682 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2683 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2684 | } |
| 2685 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2686 | // Test the request-challenge-retry sequence for basic auth. |
| 2687 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2688 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2689 | HttpRequestInfo request; |
| 2690 | request.method = "GET"; |
| 2691 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2692 | request.traffic_annotation = |
| 2693 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2694 | |
| 2695 | TestNetLog log; |
| 2696 | MockHostResolver* resolver = new MockHostResolver(); |
| 2697 | session_deps_.net_log = &log; |
| 2698 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2699 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2701 | |
| 2702 | resolver->rules()->ClearRules(); |
| 2703 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2704 | |
| 2705 | MockWrite data_writes1[] = { |
| 2706 | MockWrite("GET / HTTP/1.1\r\n" |
| 2707 | "Host: www.example.org\r\n" |
| 2708 | "Connection: keep-alive\r\n\r\n"), |
| 2709 | }; |
| 2710 | |
| 2711 | MockRead data_reads1[] = { |
| 2712 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2713 | // Give a couple authenticate options (only the middle one is actually |
| 2714 | // supported). |
| 2715 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2716 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2717 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2718 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2719 | // Large content-length -- won't matter, as connection will be reset. |
| 2720 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2721 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2722 | }; |
| 2723 | |
| 2724 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2725 | // be issuing -- the final header line contains the credentials. |
| 2726 | MockWrite data_writes2[] = { |
| 2727 | MockWrite("GET / HTTP/1.1\r\n" |
| 2728 | "Host: www.example.org\r\n" |
| 2729 | "Connection: keep-alive\r\n" |
| 2730 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2731 | }; |
| 2732 | |
| 2733 | // Lastly, the server responds with the actual content. |
| 2734 | MockRead data_reads2[] = { |
| 2735 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2736 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2737 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2738 | }; |
| 2739 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2740 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2741 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2742 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2743 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2744 | |
| 2745 | TestCompletionCallback callback1; |
| 2746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2747 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2748 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2749 | |
| 2750 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2751 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2752 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2753 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2754 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2755 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2756 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2757 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2759 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2760 | ASSERT_TRUE(response); |
| 2761 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2762 | |
| 2763 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2764 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2765 | ASSERT_FALSE(endpoint.address().empty()); |
| 2766 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2767 | |
| 2768 | resolver->rules()->ClearRules(); |
| 2769 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2770 | |
| 2771 | TestCompletionCallback callback2; |
| 2772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2773 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2774 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2775 | |
| 2776 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2777 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2778 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2779 | // The load timing after restart should have a new socket ID, and times after |
| 2780 | // those of the first load timing. |
| 2781 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2782 | load_timing_info2.connect_timing.connect_start); |
| 2783 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2784 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2785 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2786 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2787 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2790 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2791 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2792 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2793 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2795 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2796 | ASSERT_FALSE(endpoint.address().empty()); |
| 2797 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2798 | } |
| 2799 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2800 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2801 | // will eventually give up. |
| 2802 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2803 | HttpRequestInfo request; |
| 2804 | request.method = "GET"; |
| 2805 | request.url = GURL("http://www.example.org/"); |
| 2806 | request.traffic_annotation = |
| 2807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2808 | |
| 2809 | TestNetLog log; |
| 2810 | session_deps_.net_log = &log; |
| 2811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2813 | |
| 2814 | MockWrite data_writes[] = { |
| 2815 | MockWrite("GET / HTTP/1.1\r\n" |
| 2816 | "Host: www.example.org\r\n" |
| 2817 | "Connection: keep-alive\r\n\r\n"), |
| 2818 | }; |
| 2819 | |
| 2820 | MockRead data_reads[] = { |
| 2821 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2822 | // Give a couple authenticate options (only the middle one is actually |
| 2823 | // supported). |
| 2824 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2825 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2826 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2827 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2828 | // Large content-length -- won't matter, as connection will be reset. |
| 2829 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2830 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2831 | }; |
| 2832 | |
| 2833 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2834 | // be issuing -- the final header line contains the credentials. |
| 2835 | MockWrite data_writes_restart[] = { |
| 2836 | MockWrite("GET / HTTP/1.1\r\n" |
| 2837 | "Host: www.example.org\r\n" |
| 2838 | "Connection: keep-alive\r\n" |
| 2839 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2840 | }; |
| 2841 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2842 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2844 | |
| 2845 | TestCompletionCallback callback; |
| 2846 | int rv = callback.GetResult( |
| 2847 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2848 | |
| 2849 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2850 | for (int i = 0; i < 32; i++) { |
| 2851 | // Check the previous response was a 401. |
| 2852 | EXPECT_THAT(rv, IsOk()); |
| 2853 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2854 | ASSERT_TRUE(response); |
| 2855 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2856 | |
| 2857 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2858 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2859 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2860 | data_restarts.back().get()); |
| 2861 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2862 | callback.callback())); |
| 2863 | } |
| 2864 | |
| 2865 | // After too many tries, the transaction should have given up. |
| 2866 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2867 | } |
| 2868 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2869 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2870 | HttpRequestInfo request; |
| 2871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2872 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2873 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2874 | request.traffic_annotation = |
| 2875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2879 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2880 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2881 | MockWrite( |
| 2882 | "GET / HTTP/1.1\r\n" |
| 2883 | "Host: www.example.org\r\n" |
| 2884 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2885 | }; |
| 2886 | |
| 2887 | MockRead data_reads[] = { |
| 2888 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2889 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2890 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2891 | // Large content-length -- won't matter, as connection will be reset. |
| 2892 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2893 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2894 | }; |
| 2895 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2896 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2897 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2898 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2899 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2900 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2902 | |
| 2903 | rv = callback.WaitForResult(); |
| 2904 | EXPECT_EQ(0, rv); |
| 2905 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2906 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2907 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2908 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2909 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2912 | ASSERT_TRUE(response); |
| 2913 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2914 | } |
| 2915 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2916 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2917 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2918 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2919 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2920 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2921 | // reused. See http://crbug.com/544255. |
| 2922 | for (int i = 0; i < 2; ++i) { |
| 2923 | HttpRequestInfo request; |
| 2924 | request.method = "GET"; |
| 2925 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2926 | request.traffic_annotation = |
| 2927 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2928 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2929 | TestNetLog log; |
| 2930 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2932 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2933 | MockWrite data_writes[] = { |
| 2934 | MockWrite(ASYNC, 0, |
| 2935 | "GET / HTTP/1.1\r\n" |
| 2936 | "Host: www.example.org\r\n" |
| 2937 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2939 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2940 | // be issuing -- the final header line contains the credentials. |
| 2941 | MockWrite(ASYNC, 6, |
| 2942 | "GET / HTTP/1.1\r\n" |
| 2943 | "Host: www.example.org\r\n" |
| 2944 | "Connection: keep-alive\r\n" |
| 2945 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2946 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2947 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2948 | MockRead data_reads[] = { |
| 2949 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2950 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2951 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2952 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2953 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2954 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2955 | // Lastly, the server responds with the actual content. |
| 2956 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2957 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2958 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2959 | MockRead(ASYNC, 10, "Hello"), |
| 2960 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2961 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2962 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2963 | data.set_busy_before_sync_reads(true); |
| 2964 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2965 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2966 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2968 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2969 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2970 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2971 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2972 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2973 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2974 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2976 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2977 | ASSERT_TRUE(response); |
| 2978 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2979 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2980 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2981 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2982 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2983 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2984 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2985 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2986 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2987 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2988 | TestLoadTimingReused(load_timing_info2); |
| 2989 | // The load timing after restart should have the same socket ID, and times |
| 2990 | // those of the first load timing. |
| 2991 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2992 | load_timing_info2.send_start); |
| 2993 | 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] | 2994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2995 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2996 | ASSERT_TRUE(response); |
| 2997 | EXPECT_FALSE(response->auth_challenge); |
| 2998 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2999 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3000 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3001 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3002 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3003 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3004 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3005 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3006 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3007 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3011 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3012 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3013 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3014 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3015 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3016 | request.traffic_annotation = |
| 3017 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3020 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3021 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3022 | MockWrite("GET / HTTP/1.1\r\n" |
| 3023 | "Host: www.example.org\r\n" |
| 3024 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3026 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3027 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3028 | MockWrite("GET / HTTP/1.1\r\n" |
| 3029 | "Host: www.example.org\r\n" |
| 3030 | "Connection: keep-alive\r\n" |
| 3031 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3032 | }; |
| 3033 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3034 | MockRead data_reads1[] = { |
| 3035 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3036 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3037 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3038 | |
| 3039 | // Lastly, the server responds with the actual content. |
| 3040 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3041 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3042 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3043 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3044 | }; |
| 3045 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3046 | // An incorrect reconnect would cause this to be read. |
| 3047 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3048 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3049 | }; |
| 3050 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3051 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3052 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3053 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3054 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3056 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3058 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3059 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3061 | |
| 3062 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3063 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3065 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3066 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3067 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3069 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3071 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3073 | |
| 3074 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3077 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3078 | ASSERT_TRUE(response); |
| 3079 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3080 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3084 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3085 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3086 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3088 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3089 | request.traffic_annotation = |
| 3090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3091 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3093 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3094 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3095 | MockWrite("GET / HTTP/1.1\r\n" |
| 3096 | "Host: www.example.org\r\n" |
| 3097 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3099 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3100 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3101 | MockWrite("GET / HTTP/1.1\r\n" |
| 3102 | "Host: www.example.org\r\n" |
| 3103 | "Connection: keep-alive\r\n" |
| 3104 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3105 | }; |
| 3106 | |
| 3107 | // Respond with 5 kb of response body. |
| 3108 | std::string large_body_string("Unauthorized"); |
| 3109 | large_body_string.append(5 * 1024, ' '); |
| 3110 | large_body_string.append("\r\n"); |
| 3111 | |
| 3112 | MockRead data_reads1[] = { |
| 3113 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3114 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3115 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3116 | // 5134 = 12 + 5 * 1024 + 2 |
| 3117 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3118 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3119 | |
| 3120 | // Lastly, the server responds with the actual content. |
| 3121 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3122 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3123 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3124 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3125 | }; |
| 3126 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3127 | // An incorrect reconnect would cause this to be read. |
| 3128 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3129 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3130 | }; |
| 3131 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3132 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3133 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3134 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3135 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3137 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3140 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3142 | |
| 3143 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3146 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3147 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3148 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3150 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3151 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3152 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3154 | |
| 3155 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3156 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3158 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3159 | ASSERT_TRUE(response); |
| 3160 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3161 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3165 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3166 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3167 | HttpRequestInfo request; |
| 3168 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3169 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3170 | request.traffic_annotation = |
| 3171 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3172 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3174 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3175 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3176 | MockWrite( |
| 3177 | "GET / HTTP/1.1\r\n" |
| 3178 | "Host: www.example.org\r\n" |
| 3179 | "Connection: keep-alive\r\n\r\n"), |
| 3180 | // This simulates the seemingly successful write to a closed connection |
| 3181 | // if the bug is not fixed. |
| 3182 | MockWrite( |
| 3183 | "GET / HTTP/1.1\r\n" |
| 3184 | "Host: www.example.org\r\n" |
| 3185 | "Connection: keep-alive\r\n" |
| 3186 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3187 | }; |
| 3188 | |
| 3189 | MockRead data_reads1[] = { |
| 3190 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3191 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3192 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3193 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3194 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3195 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3196 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3197 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3198 | }; |
| 3199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3200 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3201 | // be issuing -- the final header line contains the credentials. |
| 3202 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3203 | MockWrite( |
| 3204 | "GET / HTTP/1.1\r\n" |
| 3205 | "Host: www.example.org\r\n" |
| 3206 | "Connection: keep-alive\r\n" |
| 3207 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3208 | }; |
| 3209 | |
| 3210 | // Lastly, the server responds with the actual content. |
| 3211 | MockRead data_reads2[] = { |
| 3212 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3213 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3214 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3215 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3216 | }; |
| 3217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3218 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3219 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3221 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3223 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3226 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3228 | |
| 3229 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3232 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3233 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3234 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3236 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3238 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3240 | |
| 3241 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3244 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3245 | ASSERT_TRUE(response); |
| 3246 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3247 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3248 | } |
| 3249 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3250 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3251 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3252 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3253 | HttpRequestInfo request; |
| 3254 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3255 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3256 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3257 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3258 | request.traffic_annotation = |
| 3259 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3260 | |
| 3261 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3262 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3263 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3264 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3265 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3266 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3268 | |
| 3269 | // Since we have proxy, should try to establish tunnel. |
| 3270 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3271 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3272 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3273 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3274 | }; |
| 3275 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3276 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | // connection. |
| 3278 | MockRead data_reads1[] = { |
| 3279 | // No credentials. |
| 3280 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3281 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3282 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3283 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3284 | // Since the first connection couldn't be reused, need to establish another |
| 3285 | // once given credentials. |
| 3286 | MockWrite data_writes2[] = { |
| 3287 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3288 | // be issuing -- the final header line contains the credentials. |
| 3289 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3290 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3291 | "Proxy-Connection: keep-alive\r\n" |
| 3292 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3293 | |
| 3294 | MockWrite("GET / HTTP/1.1\r\n" |
| 3295 | "Host: www.example.org\r\n" |
| 3296 | "Connection: keep-alive\r\n\r\n"), |
| 3297 | }; |
| 3298 | |
| 3299 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3300 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3301 | |
| 3302 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3303 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3304 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3305 | MockRead(SYNCHRONOUS, "hello"), |
| 3306 | }; |
| 3307 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3308 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3309 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3310 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3311 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3312 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3314 | |
| 3315 | TestCompletionCallback callback1; |
| 3316 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3317 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3318 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3319 | |
| 3320 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3322 | |
| 3323 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3324 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3325 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3326 | log.GetEntries(&entries); |
| 3327 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3328 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3329 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3331 | entries, pos, |
| 3332 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3333 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3334 | |
| 3335 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3336 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3338 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | EXPECT_EQ(407, response->headers->response_code()); |
| 3340 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3341 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3342 | |
| 3343 | LoadTimingInfo load_timing_info; |
| 3344 | // CONNECT requests and responses are handled at the connect job level, so |
| 3345 | // the transaction does not yet have a connection. |
| 3346 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3347 | |
| 3348 | TestCompletionCallback callback2; |
| 3349 | |
| 3350 | rv = |
| 3351 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3352 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3353 | |
| 3354 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3355 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | |
| 3357 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3358 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | |
| 3360 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3361 | EXPECT_EQ(200, response->headers->response_code()); |
| 3362 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3363 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3364 | |
| 3365 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3366 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3367 | |
| 3368 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3369 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3370 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3371 | |
| 3372 | trans.reset(); |
| 3373 | session->CloseAllConnections(); |
| 3374 | } |
| 3375 | |
| 3376 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3377 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3378 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3379 | HttpRequestInfo request; |
| 3380 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3381 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3382 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3383 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3384 | request.traffic_annotation = |
| 3385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3386 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3387 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3388 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3389 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3390 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3391 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3392 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3394 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3395 | // Since we have proxy, should try to establish tunnel. |
| 3396 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3397 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3398 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3399 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3400 | }; |
| 3401 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3402 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3403 | // connection. |
| 3404 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3405 | // No credentials. |
| 3406 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3407 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3408 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3409 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3410 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3411 | MockWrite data_writes2[] = { |
| 3412 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3413 | // be issuing -- the final header line contains the credentials. |
| 3414 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3415 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3416 | "Proxy-Connection: keep-alive\r\n" |
| 3417 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3418 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3419 | MockWrite("GET / HTTP/1.1\r\n" |
| 3420 | "Host: www.example.org\r\n" |
| 3421 | "Connection: keep-alive\r\n\r\n"), |
| 3422 | }; |
| 3423 | |
| 3424 | MockRead data_reads2[] = { |
| 3425 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3426 | |
| 3427 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3428 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3429 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3430 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3431 | }; |
| 3432 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3433 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3434 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3435 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3436 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3437 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3440 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3441 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3442 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3443 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3445 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3447 | |
| 3448 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3449 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3450 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3451 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3452 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3453 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3454 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3455 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3456 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3457 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3458 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3459 | |
| 3460 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3461 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3462 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3463 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3464 | EXPECT_EQ(407, response->headers->response_code()); |
| 3465 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3466 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3468 | LoadTimingInfo load_timing_info; |
| 3469 | // CONNECT requests and responses are handled at the connect job level, so |
| 3470 | // the transaction does not yet have a connection. |
| 3471 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3473 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3475 | rv = trans->RestartWithAuth( |
| 3476 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3478 | |
| 3479 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3481 | |
| 3482 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3483 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3484 | |
| 3485 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3486 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3487 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3488 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3489 | |
| 3490 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3491 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3492 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3493 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3494 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3495 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3496 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3497 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3498 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3499 | } |
| 3500 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3501 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3502 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3503 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3504 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3505 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3506 | // reused. See http://crbug.com/544255. |
| 3507 | for (int i = 0; i < 2; ++i) { |
| 3508 | HttpRequestInfo request; |
| 3509 | request.method = "GET"; |
| 3510 | request.url = GURL("https://www.example.org/"); |
| 3511 | // Ensure that proxy authentication is attempted even |
| 3512 | // when the no authentication data flag is set. |
| 3513 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3514 | request.traffic_annotation = |
| 3515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3516 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3517 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3518 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3519 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3520 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3521 | BoundTestNetLog log; |
| 3522 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3524 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3525 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3526 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3527 | // Since we have proxy, should try to establish tunnel. |
| 3528 | MockWrite data_writes1[] = { |
| 3529 | MockWrite(ASYNC, 0, |
| 3530 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3531 | "Host: www.example.org:443\r\n" |
| 3532 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3534 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3535 | // be issuing -- the final header line contains the credentials. |
| 3536 | MockWrite(ASYNC, 3, |
| 3537 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3538 | "Host: www.example.org:443\r\n" |
| 3539 | "Proxy-Connection: keep-alive\r\n" |
| 3540 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3541 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3542 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3543 | // The proxy responds to the connect with a 407, using a persistent |
| 3544 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3545 | MockRead data_reads1[] = { |
| 3546 | // No credentials. |
| 3547 | MockRead(ASYNC, 1, |
| 3548 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3549 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3550 | "Proxy-Connection: keep-alive\r\n" |
| 3551 | "Content-Length: 10\r\n\r\n"), |
| 3552 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3553 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | // Wrong credentials (wrong password). |
| 3555 | MockRead(ASYNC, 4, |
| 3556 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3557 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3558 | "Proxy-Connection: keep-alive\r\n" |
| 3559 | "Content-Length: 10\r\n\r\n"), |
| 3560 | // No response body because the test stops reading here. |
| 3561 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3562 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3563 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3564 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3565 | data1.set_busy_before_sync_reads(true); |
| 3566 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3567 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3568 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3570 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3571 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3572 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3573 | TestNetLogEntry::List entries; |
| 3574 | log.GetEntries(&entries); |
| 3575 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3576 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3577 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3578 | ExpectLogContainsSomewhere( |
| 3579 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3580 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3581 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3583 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3584 | ASSERT_TRUE(response); |
| 3585 | ASSERT_TRUE(response->headers); |
| 3586 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3587 | EXPECT_EQ(407, response->headers->response_code()); |
| 3588 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3589 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3590 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3591 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3592 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3593 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3594 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3595 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3596 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3597 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3598 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3599 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3600 | ASSERT_TRUE(response); |
| 3601 | ASSERT_TRUE(response->headers); |
| 3602 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3603 | EXPECT_EQ(407, response->headers->response_code()); |
| 3604 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3605 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3606 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3607 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3608 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3609 | // out of scope. |
| 3610 | session->CloseAllConnections(); |
| 3611 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3615 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3616 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3617 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3618 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3619 | // reused. See http://crbug.com/544255. |
| 3620 | for (int i = 0; i < 2; ++i) { |
| 3621 | HttpRequestInfo request; |
| 3622 | request.method = "GET"; |
| 3623 | request.url = GURL("https://www.example.org/"); |
| 3624 | // Ensure that proxy authentication is attempted even |
| 3625 | // when the no authentication data flag is set. |
| 3626 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3627 | request.traffic_annotation = |
| 3628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3629 | |
| 3630 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3631 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3632 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3633 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3634 | BoundTestNetLog log; |
| 3635 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3636 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3639 | |
| 3640 | // Since we have proxy, should try to establish tunnel. |
| 3641 | MockWrite data_writes1[] = { |
| 3642 | MockWrite(ASYNC, 0, |
| 3643 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3644 | "Host: www.example.org:443\r\n" |
| 3645 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3647 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3648 | // be issuing -- the final header line contains the credentials. |
| 3649 | MockWrite(ASYNC, 3, |
| 3650 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3651 | "Host: www.example.org:443\r\n" |
| 3652 | "Proxy-Connection: keep-alive\r\n" |
| 3653 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3654 | }; |
| 3655 | |
| 3656 | // The proxy responds to the connect with a 407, using a persistent |
| 3657 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3658 | MockRead data_reads1[] = { |
| 3659 | // No credentials. |
| 3660 | MockRead(ASYNC, 1, |
| 3661 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3662 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3663 | "Content-Length: 10\r\n\r\n"), |
| 3664 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3665 | |
| 3666 | // Wrong credentials (wrong password). |
| 3667 | MockRead(ASYNC, 4, |
| 3668 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3669 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3670 | "Content-Length: 10\r\n\r\n"), |
| 3671 | // No response body because the test stops reading here. |
| 3672 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3673 | }; |
| 3674 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3675 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3676 | data1.set_busy_before_sync_reads(true); |
| 3677 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3678 | |
| 3679 | TestCompletionCallback callback1; |
| 3680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3681 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3682 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3683 | |
| 3684 | TestNetLogEntry::List entries; |
| 3685 | log.GetEntries(&entries); |
| 3686 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3687 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3688 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3689 | ExpectLogContainsSomewhere( |
| 3690 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3691 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3692 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3694 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3695 | ASSERT_TRUE(response); |
| 3696 | ASSERT_TRUE(response->headers); |
| 3697 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3698 | EXPECT_EQ(407, response->headers->response_code()); |
| 3699 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3700 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3701 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3702 | |
| 3703 | TestCompletionCallback callback2; |
| 3704 | |
| 3705 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3706 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3707 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3708 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3710 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3711 | ASSERT_TRUE(response); |
| 3712 | ASSERT_TRUE(response->headers); |
| 3713 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3714 | EXPECT_EQ(407, response->headers->response_code()); |
| 3715 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3716 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3717 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3718 | |
| 3719 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3720 | // out of scope. |
| 3721 | session->CloseAllConnections(); |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3726 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3727 | // the case the server sends extra data on the original socket, so it can't be |
| 3728 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3729 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3730 | HttpRequestInfo request; |
| 3731 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3732 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3733 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3734 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3735 | request.traffic_annotation = |
| 3736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3737 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3738 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3739 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3740 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3741 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3742 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3743 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3745 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3746 | // Since we have proxy, should try to establish tunnel. |
| 3747 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3748 | MockWrite(ASYNC, 0, |
| 3749 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3750 | "Host: www.example.org:443\r\n" |
| 3751 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3752 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3753 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3754 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3755 | // extra data, so the socket cannot be reused. |
| 3756 | MockRead data_reads1[] = { |
| 3757 | // No credentials. |
| 3758 | MockRead(ASYNC, 1, |
| 3759 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3760 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3761 | "Content-Length: 10\r\n\r\n"), |
| 3762 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3763 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3764 | }; |
| 3765 | |
| 3766 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3767 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3768 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3769 | MockWrite(ASYNC, 0, |
| 3770 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3771 | "Host: www.example.org:443\r\n" |
| 3772 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3773 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3774 | |
| 3775 | MockWrite(ASYNC, 2, |
| 3776 | "GET / HTTP/1.1\r\n" |
| 3777 | "Host: www.example.org\r\n" |
| 3778 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3779 | }; |
| 3780 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3781 | MockRead data_reads2[] = { |
| 3782 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3783 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3784 | MockRead(ASYNC, 3, |
| 3785 | "HTTP/1.1 200 OK\r\n" |
| 3786 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3787 | "Content-Length: 5\r\n\r\n"), |
| 3788 | // No response body because the test stops reading here. |
| 3789 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3790 | }; |
| 3791 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3792 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3793 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3794 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3795 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3796 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3797 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3799 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3800 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3801 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3802 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3803 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3804 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3805 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3806 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3807 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3808 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3809 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3810 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3811 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3812 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3813 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3814 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3815 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3816 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3817 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3819 | ASSERT_TRUE(response); |
| 3820 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3821 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3822 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3823 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3824 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3825 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3826 | LoadTimingInfo load_timing_info; |
| 3827 | // CONNECT requests and responses are handled at the connect job level, so |
| 3828 | // the transaction does not yet have a connection. |
| 3829 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3831 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3832 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3833 | rv = |
| 3834 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3835 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3836 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3837 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3838 | EXPECT_EQ(200, response->headers->response_code()); |
| 3839 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3840 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3841 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3842 | // The password prompt info should not be set. |
| 3843 | EXPECT_FALSE(response->auth_challenge); |
| 3844 | |
| 3845 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3846 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3847 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3848 | |
| 3849 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3850 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3851 | } |
| 3852 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3853 | // Test the case a proxy closes a socket while the challenge body is being |
| 3854 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3855 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3856 | HttpRequestInfo request; |
| 3857 | request.method = "GET"; |
| 3858 | request.url = GURL("https://www.example.org/"); |
| 3859 | // Ensure that proxy authentication is attempted even |
| 3860 | // when the no authentication data flag is set. |
| 3861 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3862 | request.traffic_annotation = |
| 3863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3864 | |
| 3865 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3866 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3867 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3868 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3870 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3871 | |
| 3872 | // Since we have proxy, should try to establish tunnel. |
| 3873 | MockWrite data_writes1[] = { |
| 3874 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3875 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3876 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3877 | }; |
| 3878 | |
| 3879 | // The proxy responds to the connect with a 407, using a persistent |
| 3880 | // connection. |
| 3881 | MockRead data_reads1[] = { |
| 3882 | // No credentials. |
| 3883 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3884 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3885 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3886 | // Server hands up in the middle of the body. |
| 3887 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3888 | }; |
| 3889 | |
| 3890 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3891 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3892 | // be issuing -- the final header line contains the credentials. |
| 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" |
| 3896 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3897 | |
| 3898 | MockWrite("GET / HTTP/1.1\r\n" |
| 3899 | "Host: www.example.org\r\n" |
| 3900 | "Connection: keep-alive\r\n\r\n"), |
| 3901 | }; |
| 3902 | |
| 3903 | MockRead data_reads2[] = { |
| 3904 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3905 | |
| 3906 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3908 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3909 | MockRead(SYNCHRONOUS, "hello"), |
| 3910 | }; |
| 3911 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3912 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3913 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3914 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3915 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3916 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3918 | |
| 3919 | TestCompletionCallback callback; |
| 3920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3921 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3922 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3924 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3925 | ASSERT_TRUE(response); |
| 3926 | ASSERT_TRUE(response->headers); |
| 3927 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3928 | EXPECT_EQ(407, response->headers->response_code()); |
| 3929 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3931 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3932 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3934 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3935 | ASSERT_TRUE(response); |
| 3936 | ASSERT_TRUE(response->headers); |
| 3937 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3938 | EXPECT_EQ(200, response->headers->response_code()); |
| 3939 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3940 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3941 | EXPECT_EQ("hello", body); |
| 3942 | } |
| 3943 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3944 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3945 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3946 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3947 | HttpRequestInfo request; |
| 3948 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3949 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3950 | request.traffic_annotation = |
| 3951 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3952 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3953 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3954 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3955 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3956 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3957 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3959 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3960 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3961 | // Since we have proxy, should try to establish tunnel. |
| 3962 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3963 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3964 | "Host: www.example.org:443\r\n" |
| 3965 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3966 | }; |
| 3967 | |
| 3968 | // The proxy responds to the connect with a 407. |
| 3969 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3970 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3971 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3972 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3973 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3974 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3975 | }; |
| 3976 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3977 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3980 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3982 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3984 | |
| 3985 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3988 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3989 | ASSERT_TRUE(response); |
| 3990 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3991 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3992 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3993 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | |
| 3995 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3996 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3997 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3998 | |
| 3999 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4000 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4001 | } |
| 4002 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4003 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4004 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4005 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4006 | HttpRequestInfo request; |
| 4007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4008 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4009 | request.traffic_annotation = |
| 4010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4011 | |
| 4012 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4013 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4014 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4015 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4019 | |
| 4020 | // Since we have proxy, should try to establish tunnel. |
| 4021 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4022 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4023 | "Host: www.example.org:443\r\n" |
| 4024 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4025 | }; |
| 4026 | |
| 4027 | // The proxy responds to the connect with a 407. |
| 4028 | MockRead data_reads[] = { |
| 4029 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4030 | MockRead("X-Foo: bar\r\n"), |
| 4031 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4032 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4033 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4034 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4035 | }; |
| 4036 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4037 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4039 | |
| 4040 | TestCompletionCallback callback; |
| 4041 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4042 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4044 | |
| 4045 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4046 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4049 | ASSERT_TRUE(response); |
| 4050 | ASSERT_TRUE(response->headers); |
| 4051 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4052 | EXPECT_EQ(407, response->headers->response_code()); |
| 4053 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4054 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4055 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4056 | |
| 4057 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4058 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4059 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4060 | |
| 4061 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4062 | session->CloseAllConnections(); |
| 4063 | } |
| 4064 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4065 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4066 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4067 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4068 | HttpRequestInfo request; |
| 4069 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4070 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4071 | request.traffic_annotation = |
| 4072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4073 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4074 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4076 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4077 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4078 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4079 | MockWrite( |
| 4080 | "GET / HTTP/1.1\r\n" |
| 4081 | "Host: www.example.org\r\n" |
| 4082 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4083 | }; |
| 4084 | |
| 4085 | MockRead data_reads1[] = { |
| 4086 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4087 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4088 | // Large content-length -- won't matter, as connection will be reset. |
| 4089 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4090 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4091 | }; |
| 4092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4093 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4094 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4095 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4096 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4097 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4098 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4100 | |
| 4101 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4102 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4103 | } |
| 4104 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4105 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4106 | // through a non-authenticating proxy. The request should fail with |
| 4107 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4108 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4109 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4110 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4111 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4112 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4113 | HttpRequestInfo request; |
| 4114 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4115 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4116 | request.traffic_annotation = |
| 4117 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4118 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4119 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4120 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4121 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4122 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4124 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4125 | // Since we have proxy, should try to establish tunnel. |
| 4126 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4127 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4128 | "Host: www.example.org:443\r\n" |
| 4129 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4130 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4131 | MockWrite("GET / HTTP/1.1\r\n" |
| 4132 | "Host: www.example.org\r\n" |
| 4133 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4134 | }; |
| 4135 | |
| 4136 | MockRead data_reads1[] = { |
| 4137 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4138 | |
| 4139 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4140 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4141 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4142 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4143 | }; |
| 4144 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4145 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4146 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4147 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4150 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4151 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4152 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4154 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4156 | |
| 4157 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4158 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4159 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4160 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4161 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4162 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4163 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4164 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4165 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4166 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4167 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4168 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4169 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4170 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4171 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4172 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4173 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4174 | HttpRequestInfo request; |
| 4175 | request.method = "GET"; |
| 4176 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4177 | request.traffic_annotation = |
| 4178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4179 | |
| 4180 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4181 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4182 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4183 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4184 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4185 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4186 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4187 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4188 | mock_handler->set_allows_default_credentials(true); |
| 4189 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4190 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4191 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | |
| 4193 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4194 | NetLog net_log; |
| 4195 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4196 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | |
| 4198 | // Since we have proxy, should try to establish tunnel. |
| 4199 | MockWrite data_writes1[] = { |
| 4200 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4201 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4202 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4203 | }; |
| 4204 | |
| 4205 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4206 | // connection. |
| 4207 | MockRead data_reads1[] = { |
| 4208 | // No credentials. |
| 4209 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4210 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4211 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4212 | }; |
| 4213 | |
| 4214 | // Since the first connection couldn't be reused, need to establish another |
| 4215 | // once given credentials. |
| 4216 | MockWrite data_writes2[] = { |
| 4217 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4218 | // be issuing -- the final header line contains the credentials. |
| 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" |
| 4222 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4223 | |
| 4224 | MockWrite("GET / HTTP/1.1\r\n" |
| 4225 | "Host: www.example.org\r\n" |
| 4226 | "Connection: keep-alive\r\n\r\n"), |
| 4227 | }; |
| 4228 | |
| 4229 | MockRead data_reads2[] = { |
| 4230 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4231 | |
| 4232 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4233 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4234 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4235 | MockRead(SYNCHRONOUS, "hello"), |
| 4236 | }; |
| 4237 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4238 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4239 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4240 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4241 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4242 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4243 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4244 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4245 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4246 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4247 | |
| 4248 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4249 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4250 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4251 | |
| 4252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4253 | ASSERT_TRUE(response); |
| 4254 | ASSERT_TRUE(response->headers); |
| 4255 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4256 | EXPECT_EQ(407, response->headers->response_code()); |
| 4257 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4258 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4259 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | |
| 4261 | LoadTimingInfo load_timing_info; |
| 4262 | // CONNECT requests and responses are handled at the connect job level, so |
| 4263 | // the transaction does not yet have a connection. |
| 4264 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4265 | |
| 4266 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4267 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4268 | response = trans->GetResponseInfo(); |
| 4269 | ASSERT_TRUE(response); |
| 4270 | ASSERT_TRUE(response->headers); |
| 4271 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4272 | EXPECT_EQ(200, response->headers->response_code()); |
| 4273 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4274 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4275 | |
| 4276 | // The password prompt info should not be set. |
| 4277 | EXPECT_FALSE(response->auth_challenge); |
| 4278 | |
| 4279 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4280 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4281 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4282 | |
| 4283 | trans.reset(); |
| 4284 | session->CloseAllConnections(); |
| 4285 | } |
| 4286 | |
| 4287 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4288 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4289 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4290 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4291 | HttpRequestInfo request; |
| 4292 | request.method = "GET"; |
| 4293 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4294 | request.traffic_annotation = |
| 4295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4296 | |
| 4297 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4298 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4299 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4300 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4301 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4302 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4303 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4304 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4305 | mock_handler->set_allows_default_credentials(true); |
| 4306 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4307 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4308 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | |
| 4310 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4311 | NetLog net_log; |
| 4312 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4313 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4314 | |
| 4315 | // Should try to establish tunnel. |
| 4316 | MockWrite data_writes1[] = { |
| 4317 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4318 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4319 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4320 | |
| 4321 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4322 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4323 | "Proxy-Connection: keep-alive\r\n" |
| 4324 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4325 | }; |
| 4326 | |
| 4327 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4328 | // connection. |
| 4329 | MockRead data_reads1[] = { |
| 4330 | // No credentials. |
| 4331 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4332 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4333 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4334 | }; |
| 4335 | |
| 4336 | // Since the first connection was closed, need to establish another once given |
| 4337 | // credentials. |
| 4338 | MockWrite data_writes2[] = { |
| 4339 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4340 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4341 | "Proxy-Connection: keep-alive\r\n" |
| 4342 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4343 | |
| 4344 | MockWrite("GET / HTTP/1.1\r\n" |
| 4345 | "Host: www.example.org\r\n" |
| 4346 | "Connection: keep-alive\r\n\r\n"), |
| 4347 | }; |
| 4348 | |
| 4349 | MockRead data_reads2[] = { |
| 4350 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4351 | |
| 4352 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4353 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4354 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4355 | MockRead(SYNCHRONOUS, "hello"), |
| 4356 | }; |
| 4357 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4358 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4359 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4360 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4361 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4362 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4364 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4365 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4366 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4367 | |
| 4368 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4369 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4370 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4371 | |
| 4372 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4373 | ASSERT_TRUE(response); |
| 4374 | ASSERT_TRUE(response->headers); |
| 4375 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4376 | EXPECT_EQ(407, response->headers->response_code()); |
| 4377 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4378 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4379 | EXPECT_FALSE(response->auth_challenge); |
| 4380 | |
| 4381 | LoadTimingInfo load_timing_info; |
| 4382 | // CONNECT requests and responses are handled at the connect job level, so |
| 4383 | // the transaction does not yet have a connection. |
| 4384 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4385 | |
| 4386 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4387 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4388 | |
| 4389 | response = trans->GetResponseInfo(); |
| 4390 | ASSERT_TRUE(response); |
| 4391 | ASSERT_TRUE(response->headers); |
| 4392 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4393 | EXPECT_EQ(200, response->headers->response_code()); |
| 4394 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4395 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4396 | |
| 4397 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4398 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4399 | |
| 4400 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4401 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4402 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4403 | |
| 4404 | trans.reset(); |
| 4405 | session->CloseAllConnections(); |
| 4406 | } |
| 4407 | |
| 4408 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4409 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4410 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4411 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4412 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4413 | HttpRequestInfo request; |
| 4414 | request.method = "GET"; |
| 4415 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4416 | request.traffic_annotation = |
| 4417 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4418 | |
| 4419 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4420 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4421 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4422 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4423 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4424 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4425 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4426 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4427 | mock_handler->set_allows_default_credentials(true); |
| 4428 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4429 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4430 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4431 | |
| 4432 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4433 | NetLog net_log; |
| 4434 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4435 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4436 | |
| 4437 | // Should try to establish tunnel. |
| 4438 | MockWrite data_writes1[] = { |
| 4439 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4440 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4441 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4442 | |
| 4443 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4444 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4445 | "Proxy-Connection: keep-alive\r\n" |
| 4446 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4447 | }; |
| 4448 | |
| 4449 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4450 | // second request is sent. |
| 4451 | MockRead data_reads1[] = { |
| 4452 | // No credentials. |
| 4453 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4454 | MockRead("Content-Length: 0\r\n"), |
| 4455 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4456 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4457 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4458 | }; |
| 4459 | |
| 4460 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4461 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4462 | // request. |
| 4463 | MockWrite data_writes2[] = { |
| 4464 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4465 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4466 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4467 | }; |
| 4468 | |
| 4469 | // The proxy, having had more than enough of us, just hangs up. |
| 4470 | MockRead data_reads2[] = { |
| 4471 | // No credentials. |
| 4472 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4473 | }; |
| 4474 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4475 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4476 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4477 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4478 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4479 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4480 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4481 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4482 | |
| 4483 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4484 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4485 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4486 | |
| 4487 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4488 | ASSERT_TRUE(response); |
| 4489 | ASSERT_TRUE(response->headers); |
| 4490 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4491 | EXPECT_EQ(407, response->headers->response_code()); |
| 4492 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4493 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4494 | EXPECT_FALSE(response->auth_challenge); |
| 4495 | |
| 4496 | LoadTimingInfo load_timing_info; |
| 4497 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4498 | |
| 4499 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4500 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4501 | |
| 4502 | trans.reset(); |
| 4503 | session->CloseAllConnections(); |
| 4504 | } |
| 4505 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4506 | // This test exercises an odd edge case where the proxy closes the connection |
| 4507 | // after the authentication handshake is complete. Presumably this technique is |
| 4508 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4509 | // succeeds, but the user is not authorized to connect to the destination |
| 4510 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4511 | // site. |
| 4512 | TEST_F(HttpNetworkTransactionTest, |
| 4513 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4514 | HttpRequestInfo request; |
| 4515 | request.method = "GET"; |
| 4516 | request.url = GURL("https://www.example.org/"); |
| 4517 | request.traffic_annotation = |
| 4518 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4519 | |
| 4520 | // Configure against proxy server "myproxy:70". |
| 4521 | session_deps_.proxy_resolution_service = |
| 4522 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4523 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4524 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4525 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4526 | // version interference probes. |
| 4527 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4528 | // test TLS 1.3. |
| 4529 | SSLConfig config; |
| 4530 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4531 | session_deps_.ssl_config_service = |
| 4532 | std::make_unique<TestSSLConfigService>(config); |
| 4533 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4534 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4535 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4536 | |
| 4537 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4538 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4539 | // was a real network error. |
| 4540 | // |
| 4541 | // The handlers support both default and explicit credentials. The retry |
| 4542 | // mentioned above should be able to reuse the default identity. Thus there |
| 4543 | // should never be a need to prompt for explicit credentials. |
| 4544 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4545 | mock_handler->set_allows_default_credentials(true); |
| 4546 | mock_handler->set_allows_explicit_credentials(true); |
| 4547 | mock_handler->set_connection_based(true); |
| 4548 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4549 | HttpAuth::AUTH_PROXY); |
| 4550 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4551 | mock_handler->set_allows_default_credentials(true); |
| 4552 | mock_handler->set_allows_explicit_credentials(true); |
| 4553 | mock_handler->set_connection_based(true); |
| 4554 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4555 | HttpAuth::AUTH_PROXY); |
| 4556 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4557 | |
| 4558 | NetLog net_log; |
| 4559 | session_deps_.net_log = &net_log; |
| 4560 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4561 | |
| 4562 | // Data for both sockets. |
| 4563 | // |
| 4564 | // Writes are for the tunnel establishment attempts and the |
| 4565 | // authentication handshake. |
| 4566 | MockWrite data_writes1[] = { |
| 4567 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4568 | "Host: www.example.org:443\r\n" |
| 4569 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4570 | |
| 4571 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4572 | "Host: www.example.org:443\r\n" |
| 4573 | "Proxy-Connection: keep-alive\r\n" |
| 4574 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4575 | |
| 4576 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4577 | "Host: www.example.org:443\r\n" |
| 4578 | "Proxy-Connection: keep-alive\r\n" |
| 4579 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4580 | }; |
| 4581 | |
| 4582 | // The server side of the authentication handshake. Note that the response to |
| 4583 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4584 | MockRead data_reads1[] = { |
| 4585 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4586 | MockRead("Content-Length: 0\r\n"), |
| 4587 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4588 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4589 | |
| 4590 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4591 | MockRead("Content-Length: 0\r\n"), |
| 4592 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4593 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4594 | |
| 4595 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4596 | }; |
| 4597 | |
| 4598 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4599 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4600 | |
| 4601 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4602 | // first attempt. |
| 4603 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4604 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4605 | |
| 4606 | auto trans = |
| 4607 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4608 | |
| 4609 | TestCompletionCallback callback; |
| 4610 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4611 | |
| 4612 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4613 | // stack. |
| 4614 | for (int i = 0; i < 4; ++i) { |
| 4615 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4616 | |
| 4617 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4618 | ASSERT_TRUE(response); |
| 4619 | ASSERT_TRUE(response->headers); |
| 4620 | EXPECT_EQ(407, response->headers->response_code()); |
| 4621 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4622 | |
| 4623 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4624 | } |
| 4625 | |
| 4626 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4627 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4628 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4629 | // being the first number, be reached, then lobbest thou thy |
| 4630 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4631 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4632 | |
| 4633 | trans.reset(); |
| 4634 | session->CloseAllConnections(); |
| 4635 | } |
| 4636 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4637 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4638 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4639 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4640 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4641 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4642 | HttpRequestInfo request; |
| 4643 | request.method = "GET"; |
| 4644 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4645 | request.traffic_annotation = |
| 4646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4647 | |
| 4648 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4649 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4650 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4651 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4652 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4653 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4654 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4655 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4656 | mock_handler->set_allows_default_credentials(true); |
| 4657 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4658 | HttpAuth::AUTH_PROXY); |
| 4659 | // Add another handler for the second challenge. It supports default |
| 4660 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4661 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4662 | mock_handler->set_allows_default_credentials(true); |
| 4663 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4664 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4665 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4666 | |
| 4667 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4668 | NetLog net_log; |
| 4669 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4670 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4671 | |
| 4672 | // Should try to establish tunnel. |
| 4673 | MockWrite data_writes1[] = { |
| 4674 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4675 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4676 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4677 | }; |
| 4678 | |
| 4679 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4680 | // connection. |
| 4681 | MockRead data_reads1[] = { |
| 4682 | // No credentials. |
| 4683 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4684 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4685 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4686 | }; |
| 4687 | |
| 4688 | // Since the first connection was closed, need to establish another once given |
| 4689 | // credentials. |
| 4690 | MockWrite data_writes2[] = { |
| 4691 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4692 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4693 | "Proxy-Connection: keep-alive\r\n" |
| 4694 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4695 | }; |
| 4696 | |
| 4697 | MockRead data_reads2[] = { |
| 4698 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4699 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4700 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4701 | }; |
| 4702 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4703 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4704 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4705 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4706 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4707 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4709 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4710 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4711 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4712 | |
| 4713 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4714 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4715 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4716 | |
| 4717 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4718 | ASSERT_TRUE(response); |
| 4719 | ASSERT_TRUE(response->headers); |
| 4720 | EXPECT_EQ(407, response->headers->response_code()); |
| 4721 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4722 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4723 | EXPECT_FALSE(response->auth_challenge); |
| 4724 | |
| 4725 | LoadTimingInfo load_timing_info; |
| 4726 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4727 | |
| 4728 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4729 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4730 | response = trans->GetResponseInfo(); |
| 4731 | ASSERT_TRUE(response); |
| 4732 | ASSERT_TRUE(response->headers); |
| 4733 | EXPECT_EQ(407, response->headers->response_code()); |
| 4734 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4735 | EXPECT_TRUE(response->auth_challenge); |
| 4736 | |
| 4737 | trans.reset(); |
| 4738 | session->CloseAllConnections(); |
| 4739 | } |
| 4740 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4741 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4742 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4743 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4744 | // authentication handshake can continue with the same scheme but with a |
| 4745 | // different identity. |
| 4746 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4747 | HttpRequestInfo request; |
| 4748 | request.method = "GET"; |
| 4749 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4750 | request.traffic_annotation = |
| 4751 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4752 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4753 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4754 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4755 | |
| 4756 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4757 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4758 | mock_handler->set_allows_default_credentials(true); |
| 4759 | mock_handler->set_allows_explicit_credentials(true); |
| 4760 | mock_handler->set_connection_based(true); |
| 4761 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4762 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4763 | HttpAuth::AUTH_SERVER); |
| 4764 | |
| 4765 | // Add another handler for the second challenge. It supports default |
| 4766 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4767 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4768 | mock_handler->set_allows_default_credentials(true); |
| 4769 | mock_handler->set_allows_explicit_credentials(true); |
| 4770 | mock_handler->set_connection_based(true); |
| 4771 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4772 | HttpAuth::AUTH_SERVER); |
| 4773 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4774 | |
| 4775 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4776 | |
| 4777 | MockWrite data_writes1[] = { |
| 4778 | MockWrite("GET / HTTP/1.1\r\n" |
| 4779 | "Host: www.example.org\r\n" |
| 4780 | "Connection: keep-alive\r\n\r\n"), |
| 4781 | }; |
| 4782 | |
| 4783 | MockRead data_reads1[] = { |
| 4784 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4785 | "WWW-Authenticate: Mock\r\n" |
| 4786 | "Connection: keep-alive\r\n\r\n"), |
| 4787 | }; |
| 4788 | |
| 4789 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4790 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4791 | // transaction procceds without an authorization header. |
| 4792 | MockWrite data_writes2[] = { |
| 4793 | MockWrite("GET / HTTP/1.1\r\n" |
| 4794 | "Host: www.example.org\r\n" |
| 4795 | "Connection: keep-alive\r\n\r\n"), |
| 4796 | }; |
| 4797 | |
| 4798 | MockRead data_reads2[] = { |
| 4799 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4800 | "WWW-Authenticate: Mock\r\n" |
| 4801 | "Connection: keep-alive\r\n\r\n"), |
| 4802 | }; |
| 4803 | |
| 4804 | MockWrite data_writes3[] = { |
| 4805 | MockWrite("GET / HTTP/1.1\r\n" |
| 4806 | "Host: www.example.org\r\n" |
| 4807 | "Connection: keep-alive\r\n" |
| 4808 | "Authorization: auth_token\r\n\r\n"), |
| 4809 | }; |
| 4810 | |
| 4811 | MockRead data_reads3[] = { |
| 4812 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4813 | "Content-Length: 5\r\n" |
| 4814 | "Content-Type: text/plain\r\n" |
| 4815 | "Connection: keep-alive\r\n\r\n" |
| 4816 | "Hello"), |
| 4817 | }; |
| 4818 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4819 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4820 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4821 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4822 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4823 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4824 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4825 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4826 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4827 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4828 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4829 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4830 | |
| 4831 | TestCompletionCallback callback; |
| 4832 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4833 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4834 | |
| 4835 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4836 | ASSERT_TRUE(response); |
| 4837 | ASSERT_TRUE(response->headers); |
| 4838 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4839 | |
| 4840 | // The following three tests assert that an authentication challenge was |
| 4841 | // received and that the stack is ready to respond to the challenge using |
| 4842 | // ambient credentials. |
| 4843 | EXPECT_EQ(401, response->headers->response_code()); |
| 4844 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4845 | EXPECT_FALSE(response->auth_challenge); |
| 4846 | |
| 4847 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4848 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4849 | response = trans->GetResponseInfo(); |
| 4850 | ASSERT_TRUE(response); |
| 4851 | ASSERT_TRUE(response->headers); |
| 4852 | |
| 4853 | // The following three tests assert that an authentication challenge was |
| 4854 | // received and that the stack needs explicit credentials before it is ready |
| 4855 | // to respond to the challenge. |
| 4856 | EXPECT_EQ(401, response->headers->response_code()); |
| 4857 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4858 | EXPECT_TRUE(response->auth_challenge); |
| 4859 | |
| 4860 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4861 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4862 | response = trans->GetResponseInfo(); |
| 4863 | ASSERT_TRUE(response); |
| 4864 | ASSERT_TRUE(response->headers); |
| 4865 | EXPECT_EQ(200, response->headers->response_code()); |
| 4866 | |
| 4867 | trans.reset(); |
| 4868 | session->CloseAllConnections(); |
| 4869 | } |
| 4870 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4871 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4872 | // schemes, based on the path of the URL being requests. |
| 4873 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4874 | public: |
| 4875 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4876 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4877 | |
| 4878 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4879 | |
| 4880 | static HostPortPair ProxyHostPortPair() { |
| 4881 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4882 | } |
| 4883 | |
| 4884 | // ProxyResolver implementation. |
| 4885 | int GetProxyForURL(const GURL& url, |
| 4886 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4887 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4888 | std::unique_ptr<Request>* request, |
| 4889 | const NetLogWithSource& /*net_log*/) override { |
| 4890 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4891 | results->set_traffic_annotation( |
| 4892 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4893 | if (url.path() == "/socks4") { |
| 4894 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4895 | return OK; |
| 4896 | } |
| 4897 | if (url.path() == "/socks5") { |
| 4898 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4899 | return OK; |
| 4900 | } |
| 4901 | if (url.path() == "/http") { |
| 4902 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4903 | return OK; |
| 4904 | } |
| 4905 | if (url.path() == "/https") { |
| 4906 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4907 | return OK; |
| 4908 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4909 | if (url.path() == "/https_trusted") { |
| 4910 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4911 | ProxyHostPortPair(), |
| 4912 | true /* is_trusted_proxy */)); |
| 4913 | return OK; |
| 4914 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4915 | NOTREACHED(); |
| 4916 | return ERR_NOT_IMPLEMENTED; |
| 4917 | } |
| 4918 | |
| 4919 | private: |
| 4920 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4921 | }; |
| 4922 | |
| 4923 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4924 | : public ProxyResolverFactory { |
| 4925 | public: |
| 4926 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4927 | : ProxyResolverFactory(false) {} |
| 4928 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4929 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4930 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4931 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4932 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4933 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4934 | return OK; |
| 4935 | } |
| 4936 | |
| 4937 | private: |
| 4938 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4939 | }; |
| 4940 | |
| 4941 | // 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] | 4942 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4943 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4944 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4945 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4946 | session_deps_.proxy_resolution_service = |
| 4947 | std::make_unique<ProxyResolutionService>( |
| 4948 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4949 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4950 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4951 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4952 | |
| 4953 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4954 | |
| 4955 | MockWrite socks_writes[] = { |
| 4956 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4957 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4958 | MockWrite(SYNCHRONOUS, |
| 4959 | "GET /socks4 HTTP/1.1\r\n" |
| 4960 | "Host: test\r\n" |
| 4961 | "Connection: keep-alive\r\n\r\n"), |
| 4962 | }; |
| 4963 | MockRead socks_reads[] = { |
| 4964 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4965 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4966 | "Connection: keep-alive\r\n" |
| 4967 | "Content-Length: 15\r\n\r\n" |
| 4968 | "SOCKS4 Response"), |
| 4969 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4970 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4971 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4972 | |
| 4973 | const char kSOCKS5Request[] = { |
| 4974 | 0x05, // Version |
| 4975 | 0x01, // Command (CONNECT) |
| 4976 | 0x00, // Reserved |
| 4977 | 0x03, // Address type (DOMAINNAME) |
| 4978 | 0x04, // Length of domain (4) |
| 4979 | 't', 'e', 's', 't', // Domain string |
| 4980 | 0x00, 0x50, // 16-bit port (80) |
| 4981 | }; |
| 4982 | MockWrite socks5_writes[] = { |
| 4983 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4984 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4985 | MockWrite(SYNCHRONOUS, |
| 4986 | "GET /socks5 HTTP/1.1\r\n" |
| 4987 | "Host: test\r\n" |
| 4988 | "Connection: keep-alive\r\n\r\n"), |
| 4989 | }; |
| 4990 | MockRead socks5_reads[] = { |
| 4991 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4992 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4993 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4994 | "Connection: keep-alive\r\n" |
| 4995 | "Content-Length: 15\r\n\r\n" |
| 4996 | "SOCKS5 Response"), |
| 4997 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4998 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4999 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5000 | |
| 5001 | MockWrite http_writes[] = { |
| 5002 | MockWrite(SYNCHRONOUS, |
| 5003 | "GET http://test/http HTTP/1.1\r\n" |
| 5004 | "Host: test\r\n" |
| 5005 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5006 | }; |
| 5007 | MockRead http_reads[] = { |
| 5008 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5009 | "Proxy-Connection: keep-alive\r\n" |
| 5010 | "Content-Length: 13\r\n\r\n" |
| 5011 | "HTTP Response"), |
| 5012 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5013 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5014 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5015 | |
| 5016 | MockWrite https_writes[] = { |
| 5017 | MockWrite(SYNCHRONOUS, |
| 5018 | "GET http://test/https HTTP/1.1\r\n" |
| 5019 | "Host: test\r\n" |
| 5020 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5021 | }; |
| 5022 | MockRead https_reads[] = { |
| 5023 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5024 | "Proxy-Connection: keep-alive\r\n" |
| 5025 | "Content-Length: 14\r\n\r\n" |
| 5026 | "HTTPS Response"), |
| 5027 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5028 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5029 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5030 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5031 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5032 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5033 | MockWrite https_trusted_writes[] = { |
| 5034 | MockWrite(SYNCHRONOUS, |
| 5035 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5036 | "Host: test\r\n" |
| 5037 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5038 | }; |
| 5039 | MockRead https_trusted_reads[] = { |
| 5040 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5041 | "Proxy-Connection: keep-alive\r\n" |
| 5042 | "Content-Length: 22\r\n\r\n" |
| 5043 | "HTTPS Trusted Response"), |
| 5044 | }; |
| 5045 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5046 | https_trusted_writes); |
| 5047 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5048 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5049 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5050 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5051 | struct TestCase { |
| 5052 | GURL url; |
| 5053 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5054 | // 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] | 5055 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5056 | int expected_idle_socks4_sockets; |
| 5057 | int expected_idle_socks5_sockets; |
| 5058 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5059 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5060 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5061 | int expected_idle_https_sockets; |
| 5062 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5063 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5064 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5065 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5066 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5067 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5068 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5069 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5070 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5071 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5072 | }; |
| 5073 | |
| 5074 | for (const auto& test_case : kTestCases) { |
| 5075 | HttpRequestInfo request; |
| 5076 | request.method = "GET"; |
| 5077 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5078 | request.traffic_annotation = |
| 5079 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5080 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5081 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5082 | session.get()); |
| 5083 | TestCompletionCallback callback; |
| 5084 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5085 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5086 | |
| 5087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5088 | ASSERT_TRUE(response); |
| 5089 | ASSERT_TRUE(response->headers); |
| 5090 | EXPECT_EQ(200, response->headers->response_code()); |
| 5091 | std::string response_data; |
| 5092 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5093 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5094 | |
| 5095 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5096 | // the next requests. |
| 5097 | trans.reset(); |
| 5098 | base::RunLoop().RunUntilIdle(); |
| 5099 | |
| 5100 | // Check the number of idle sockets in the pool, to make sure that used |
| 5101 | // sockets are indeed being returned to the socket pool. If each request |
| 5102 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5103 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5104 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5105 | session |
| 5106 | ->GetSocketPoolForSOCKSProxy( |
| 5107 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5108 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5109 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5110 | ProxyHostPortPair())) |
| 5111 | ->IdleSocketCount()); |
| 5112 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5113 | session |
| 5114 | ->GetSocketPoolForSOCKSProxy( |
| 5115 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5116 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5117 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5118 | ProxyHostPortPair())) |
| 5119 | ->IdleSocketCount()); |
| 5120 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5121 | session |
| 5122 | ->GetSocketPoolForHTTPLikeProxy( |
| 5123 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5124 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5125 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5126 | ProxyHostPortPair())) |
| 5127 | ->IdleSocketCount()); |
| 5128 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5129 | session |
| 5130 | ->GetSocketPoolForHTTPLikeProxy( |
| 5131 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5132 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5133 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5134 | ProxyHostPortPair())) |
| 5135 | ->IdleSocketCount()); |
| 5136 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5137 | session |
| 5138 | ->GetSocketPoolForHTTPLikeProxy( |
| 5139 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5140 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5141 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5142 | ProxyHostPortPair(), |
| 5143 | true /* is_trusted_proxy */)) |
| 5144 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5145 | } |
| 5146 | } |
| 5147 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5148 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5149 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5150 | HttpRequestInfo request1; |
| 5151 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5152 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5153 | request1.traffic_annotation = |
| 5154 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5155 | |
| 5156 | HttpRequestInfo request2; |
| 5157 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5158 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5159 | request2.traffic_annotation = |
| 5160 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5161 | |
| 5162 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5163 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5164 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5165 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5166 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5167 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5168 | |
| 5169 | // Since we have proxy, should try to establish tunnel. |
| 5170 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5171 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5172 | "Host: www.example.org:443\r\n" |
| 5173 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5174 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5175 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5176 | "Host: www.example.org\r\n" |
| 5177 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5178 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5179 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5180 | "Host: www.example.org\r\n" |
| 5181 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5182 | }; |
| 5183 | |
| 5184 | // The proxy responds to the connect with a 407, using a persistent |
| 5185 | // connection. |
| 5186 | MockRead data_reads1[] = { |
| 5187 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5188 | |
| 5189 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5190 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5191 | MockRead(SYNCHRONOUS, "1"), |
| 5192 | |
| 5193 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5194 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5195 | MockRead(SYNCHRONOUS, "22"), |
| 5196 | }; |
| 5197 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5198 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5199 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5200 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5202 | |
| 5203 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5204 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5205 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5206 | |
| 5207 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5208 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5209 | |
| 5210 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5211 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5212 | |
| 5213 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5214 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5215 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5216 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5217 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5218 | |
| 5219 | LoadTimingInfo load_timing_info1; |
| 5220 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5221 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5222 | |
| 5223 | trans1.reset(); |
| 5224 | |
| 5225 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5226 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5227 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5228 | |
| 5229 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5231 | |
| 5232 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5234 | |
| 5235 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5236 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5237 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5238 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5239 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5240 | |
| 5241 | LoadTimingInfo load_timing_info2; |
| 5242 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5243 | TestLoadTimingReused(load_timing_info2); |
| 5244 | |
| 5245 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5246 | |
| 5247 | trans2.reset(); |
| 5248 | session->CloseAllConnections(); |
| 5249 | } |
| 5250 | |
| 5251 | // 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] | 5252 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5253 | HttpRequestInfo request1; |
| 5254 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5255 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5256 | request1.traffic_annotation = |
| 5257 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5258 | |
| 5259 | HttpRequestInfo request2; |
| 5260 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5261 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5262 | request2.traffic_annotation = |
| 5263 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5264 | |
| 5265 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5266 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5267 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5268 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5269 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5270 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5272 | |
| 5273 | // Since we have proxy, should try to establish tunnel. |
| 5274 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5275 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5276 | "Host: www.example.org:443\r\n" |
| 5277 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5278 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5279 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5280 | "Host: www.example.org\r\n" |
| 5281 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5282 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5283 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5284 | "Host: www.example.org\r\n" |
| 5285 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5286 | }; |
| 5287 | |
| 5288 | // The proxy responds to the connect with a 407, using a persistent |
| 5289 | // connection. |
| 5290 | MockRead data_reads1[] = { |
| 5291 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5292 | |
| 5293 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5294 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5295 | MockRead(SYNCHRONOUS, "1"), |
| 5296 | |
| 5297 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5298 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5299 | MockRead(SYNCHRONOUS, "22"), |
| 5300 | }; |
| 5301 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5302 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5303 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5304 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5306 | |
| 5307 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5308 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5309 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5310 | |
| 5311 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5313 | |
| 5314 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5315 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5316 | |
| 5317 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5318 | ASSERT_TRUE(response1); |
| 5319 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5320 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5321 | |
| 5322 | LoadTimingInfo load_timing_info1; |
| 5323 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5324 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5325 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5326 | |
| 5327 | trans1.reset(); |
| 5328 | |
| 5329 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5330 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5331 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5332 | |
| 5333 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5335 | |
| 5336 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5337 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5338 | |
| 5339 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5340 | ASSERT_TRUE(response2); |
| 5341 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5342 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5343 | |
| 5344 | LoadTimingInfo load_timing_info2; |
| 5345 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5346 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5347 | |
| 5348 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5349 | |
| 5350 | trans2.reset(); |
| 5351 | session->CloseAllConnections(); |
| 5352 | } |
| 5353 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5354 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5355 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5356 | HttpRequestInfo request; |
| 5357 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5358 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5359 | request.traffic_annotation = |
| 5360 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5361 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5362 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5363 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5364 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5365 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5366 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5367 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5368 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5369 | // Since we have proxy, should use full url |
| 5370 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5371 | MockWrite( |
| 5372 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5373 | "Host: www.example.org\r\n" |
| 5374 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5375 | }; |
| 5376 | |
| 5377 | MockRead data_reads1[] = { |
| 5378 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5379 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5380 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5381 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5382 | }; |
| 5383 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5384 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5385 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5386 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5387 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5389 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5391 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5393 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5395 | |
| 5396 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5398 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5399 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5400 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5401 | TestLoadTimingNotReused(load_timing_info, |
| 5402 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5404 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5405 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5406 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5407 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5408 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5409 | EXPECT_EQ(200, response->headers->response_code()); |
| 5410 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5411 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5412 | |
| 5413 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5414 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5415 | } |
| 5416 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5417 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5418 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5419 | HttpRequestInfo request; |
| 5420 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5421 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5422 | request.traffic_annotation = |
| 5423 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5424 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5425 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5426 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5427 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5428 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5429 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5431 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5432 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5433 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5434 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5435 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5436 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5437 | spdy::SpdySerializedFrame resp( |
| 5438 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5439 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5440 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5441 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5442 | }; |
| 5443 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5444 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5445 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5446 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5447 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5448 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5451 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5453 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5455 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5457 | |
| 5458 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5460 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5461 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5462 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5463 | TestLoadTimingNotReused(load_timing_info, |
| 5464 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5466 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5467 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5468 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5469 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5470 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5471 | |
| 5472 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5474 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5475 | } |
| 5476 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5477 | // Verifies that a session which races and wins against the owning transaction |
| 5478 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5479 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5480 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5481 | HttpRequestInfo request; |
| 5482 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5483 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5484 | request.traffic_annotation = |
| 5485 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5486 | |
| 5487 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5488 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5489 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5490 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5491 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5493 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5494 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5495 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5496 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5497 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5498 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5499 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5500 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5501 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5502 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5503 | }; |
| 5504 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5505 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5506 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5507 | |
| 5508 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5509 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5510 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5511 | |
| 5512 | TestCompletionCallback callback1; |
| 5513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5514 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5515 | |
| 5516 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5517 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5519 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5521 | |
| 5522 | // Race a session to the proxy, which completes first. |
| 5523 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5524 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5525 | PRIVACY_MODE_DISABLED, |
| 5526 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5527 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5528 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5529 | |
| 5530 | // Unstall the resolution begun by the transaction. |
| 5531 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5532 | session_deps_.host_resolver->ResolveAllPending(); |
| 5533 | |
| 5534 | EXPECT_FALSE(callback1.have_result()); |
| 5535 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5536 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5538 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5539 | ASSERT_TRUE(response); |
| 5540 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5541 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5542 | |
| 5543 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5544 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5545 | EXPECT_EQ(kUploadData, response_data); |
| 5546 | } |
| 5547 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5548 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5549 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5550 | HttpRequestInfo request; |
| 5551 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5552 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5553 | request.traffic_annotation = |
| 5554 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5555 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5556 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5557 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5558 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5559 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5560 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5562 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5563 | // The first request will be a bare GET, the second request will be a |
| 5564 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5565 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5566 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5567 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5568 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5569 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5570 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5571 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5572 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5573 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5574 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5575 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5576 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5577 | }; |
| 5578 | |
| 5579 | // The first response is a 407 proxy authentication challenge, and the second |
| 5580 | // response will be a 200 response since the second request includes a valid |
| 5581 | // Authorization header. |
| 5582 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5583 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5584 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5585 | spdy::SpdySerializedFrame resp_authentication( |
| 5586 | spdy_util_.ConstructSpdyReplyError( |
| 5587 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5588 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5589 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5590 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5591 | spdy::SpdySerializedFrame resp_data( |
| 5592 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5593 | spdy::SpdySerializedFrame body_data( |
| 5594 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5595 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5596 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5597 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5598 | CreateMockRead(resp_data, 4), |
| 5599 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5600 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5601 | }; |
| 5602 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5603 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5605 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5606 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5607 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5610 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5613 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5614 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5616 | |
| 5617 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5620 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5621 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5622 | ASSERT_TRUE(response); |
| 5623 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5624 | EXPECT_EQ(407, response->headers->response_code()); |
| 5625 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5626 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5628 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5630 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | |
| 5633 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5634 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5635 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5636 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5637 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5638 | ASSERT_TRUE(response_restart); |
| 5639 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5640 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5641 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5642 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5643 | } |
| 5644 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5645 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5646 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5647 | HttpRequestInfo request; |
| 5648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5649 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5650 | request.traffic_annotation = |
| 5651 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5652 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5653 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5654 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5655 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5656 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5657 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5661 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5662 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5663 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5664 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5665 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5666 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5667 | const char get[] = |
| 5668 | "GET / HTTP/1.1\r\n" |
| 5669 | "Host: www.example.org\r\n" |
| 5670 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5671 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5672 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5673 | spdy::SpdySerializedFrame conn_resp( |
| 5674 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5675 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5676 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5677 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5678 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5679 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5680 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5681 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5682 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5683 | |
| 5684 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5685 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5686 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5687 | }; |
| 5688 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5689 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5690 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5691 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5692 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5693 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5694 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5695 | }; |
| 5696 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5697 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5698 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5699 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5700 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5701 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5702 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5703 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5704 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5706 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5708 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5710 | |
| 5711 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5712 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5713 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5714 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5715 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5716 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5719 | ASSERT_TRUE(response); |
| 5720 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5721 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5722 | |
| 5723 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5724 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5725 | EXPECT_EQ("1234567890", response_data); |
| 5726 | } |
| 5727 | |
| 5728 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5729 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5730 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5731 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5732 | HttpRequestInfo request; |
| 5733 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5734 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5735 | request.traffic_annotation = |
| 5736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5737 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5738 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5739 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5740 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5741 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5742 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5745 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5746 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5747 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5748 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5749 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5750 | // fetch https://www.example.org/ via SPDY |
| 5751 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5752 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5753 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5754 | spdy::SpdySerializedFrame wrapped_get( |
| 5755 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5756 | spdy::SpdySerializedFrame conn_resp( |
| 5757 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5758 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5759 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5760 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5761 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5762 | spdy::SpdySerializedFrame body( |
| 5763 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5764 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5765 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5766 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5767 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5768 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5769 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5770 | |
| 5771 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5772 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5773 | CreateMockWrite(window_update_get_resp, 6), |
| 5774 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5775 | }; |
| 5776 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5777 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5778 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5779 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5780 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5781 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5782 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5783 | }; |
| 5784 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5785 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5786 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5787 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5788 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5789 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5790 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5791 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5792 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5795 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5797 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5799 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5800 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5801 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5802 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5803 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5804 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5806 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5807 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5808 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5809 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5811 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5812 | ASSERT_TRUE(response); |
| 5813 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5814 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5815 | |
| 5816 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5817 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5818 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5822 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5823 | HttpRequestInfo request; |
| 5824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5825 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5826 | request.traffic_annotation = |
| 5827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5828 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5829 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5830 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5831 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5832 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5833 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5836 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5837 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5838 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5839 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5840 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5841 | spdy::SpdySerializedFrame get( |
| 5842 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5843 | |
| 5844 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5845 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5846 | }; |
| 5847 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5848 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5849 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5850 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5851 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5852 | }; |
| 5853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5854 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5855 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5856 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5857 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5858 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5860 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5861 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5864 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5866 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5868 | |
| 5869 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5870 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5871 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5872 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5873 | } |
| 5874 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5875 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5876 | // is observed, but does exist by the time auth credentials are provided. |
| 5877 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5878 | // what causes the existing H2 session to be noticed and reused. |
| 5879 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5880 | ProxyConfig proxy_config; |
| 5881 | proxy_config.set_auto_detect(true); |
| 5882 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5883 | |
| 5884 | CapturingProxyResolver capturing_proxy_resolver; |
| 5885 | capturing_proxy_resolver.set_proxy_server( |
| 5886 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5887 | session_deps_.proxy_resolution_service = |
| 5888 | std::make_unique<ProxyResolutionService>( |
| 5889 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5890 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5891 | std::make_unique<CapturingProxyResolverFactory>( |
| 5892 | &capturing_proxy_resolver), |
| 5893 | nullptr); |
| 5894 | |
| 5895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5896 | |
| 5897 | const char kMyUrl[] = "https://www.example.org/"; |
| 5898 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5899 | spdy::SpdySerializedFrame get_resp( |
| 5900 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5901 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5902 | |
| 5903 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5904 | spdy::SpdySerializedFrame get2( |
| 5905 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5906 | spdy::SpdySerializedFrame get_resp2( |
| 5907 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5908 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5909 | |
| 5910 | MockWrite auth_challenge_writes[] = { |
| 5911 | MockWrite(ASYNC, 0, |
| 5912 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5913 | "Host: www.example.org:443\r\n" |
| 5914 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5915 | }; |
| 5916 | |
| 5917 | MockRead auth_challenge_reads[] = { |
| 5918 | MockRead(ASYNC, 1, |
| 5919 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5920 | "Content-Length: 0\r\n" |
| 5921 | "Proxy-Connection: close\r\n" |
| 5922 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5923 | }; |
| 5924 | |
| 5925 | MockWrite spdy_writes[] = { |
| 5926 | MockWrite(ASYNC, 0, |
| 5927 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5928 | "Host: www.example.org:443\r\n" |
| 5929 | "Proxy-Connection: keep-alive\r\n" |
| 5930 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5931 | CreateMockWrite(get, 2), |
| 5932 | CreateMockWrite(get2, 5), |
| 5933 | }; |
| 5934 | |
| 5935 | MockRead spdy_reads[] = { |
| 5936 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5937 | CreateMockRead(get_resp, 3, ASYNC), |
| 5938 | CreateMockRead(body, 4, ASYNC), |
| 5939 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5940 | CreateMockRead(body2, 7, ASYNC), |
| 5941 | |
| 5942 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5943 | }; |
| 5944 | |
| 5945 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5946 | auth_challenge_writes); |
| 5947 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5948 | |
| 5949 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5950 | auth_challenge_writes); |
| 5951 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5952 | |
| 5953 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5954 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5955 | |
| 5956 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5957 | ssl.next_proto = kProtoHTTP2; |
| 5958 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5959 | |
| 5960 | TestCompletionCallback callback; |
| 5961 | std::string response_data; |
| 5962 | |
| 5963 | // Run first request until an auth challenge is observed. |
| 5964 | HttpRequestInfo request1; |
| 5965 | request1.method = "GET"; |
| 5966 | request1.url = GURL(kMyUrl); |
| 5967 | request1.traffic_annotation = |
| 5968 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5969 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5970 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5971 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5972 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5973 | ASSERT_TRUE(response); |
| 5974 | ASSERT_TRUE(response->headers); |
| 5975 | EXPECT_EQ(407, response->headers->response_code()); |
| 5976 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5977 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5978 | |
| 5979 | // Run second request until an auth challenge is observed. |
| 5980 | HttpRequestInfo request2; |
| 5981 | request2.method = "GET"; |
| 5982 | request2.url = GURL(kMyUrl); |
| 5983 | request2.traffic_annotation = |
| 5984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5985 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 5986 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 5987 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5988 | response = trans2.GetResponseInfo(); |
| 5989 | ASSERT_TRUE(response); |
| 5990 | ASSERT_TRUE(response->headers); |
| 5991 | EXPECT_EQ(407, response->headers->response_code()); |
| 5992 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5993 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5994 | |
| 5995 | // Now provide credentials for the first request, and wait for it to complete. |
| 5996 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 5997 | rv = callback.GetResult(rv); |
| 5998 | EXPECT_THAT(rv, IsOk()); |
| 5999 | response = trans1.GetResponseInfo(); |
| 6000 | ASSERT_TRUE(response); |
| 6001 | ASSERT_TRUE(response->headers); |
| 6002 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6003 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6004 | EXPECT_EQ(kUploadData, response_data); |
| 6005 | |
| 6006 | // Now provide credentials for the second request. It should notice the |
| 6007 | // existing session, and reuse it. |
| 6008 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6009 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6010 | response = trans2.GetResponseInfo(); |
| 6011 | ASSERT_TRUE(response); |
| 6012 | ASSERT_TRUE(response->headers); |
| 6013 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6014 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6015 | EXPECT_EQ(kUploadData, response_data); |
| 6016 | } |
| 6017 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6018 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6019 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6020 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6021 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6022 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6023 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6024 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6025 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6026 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6027 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6028 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6029 | |
| 6030 | HttpRequestInfo request1; |
| 6031 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6032 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6033 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6034 | request1.traffic_annotation = |
| 6035 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6036 | |
| 6037 | HttpRequestInfo request2; |
| 6038 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6039 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6040 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6041 | request2.traffic_annotation = |
| 6042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6043 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6044 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6045 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6046 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6047 | spdy::SpdySerializedFrame conn_resp1( |
| 6048 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6049 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6050 | // Fetch https://www.example.org/ via HTTP. |
| 6051 | const char get1[] = |
| 6052 | "GET / HTTP/1.1\r\n" |
| 6053 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6054 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6055 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6056 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6057 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6058 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6059 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6060 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6061 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6062 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6063 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6064 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6065 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6066 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6067 | spdy::SpdyHeaderBlock connect2_block; |
| 6068 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6069 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6070 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6071 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6072 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6073 | spdy::SpdySerializedFrame conn_resp2( |
| 6074 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6075 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6076 | // Fetch https://mail.example.org/ via HTTP. |
| 6077 | const char get2[] = |
| 6078 | "GET / HTTP/1.1\r\n" |
| 6079 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6080 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6081 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6082 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6083 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6084 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6085 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6086 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6087 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6088 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6089 | |
| 6090 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6091 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6092 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6093 | }; |
| 6094 | |
| 6095 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6096 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6097 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6098 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6099 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6100 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6101 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6102 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6103 | }; |
| 6104 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6105 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6106 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6107 | |
| 6108 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6109 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6110 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6111 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6113 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6115 | |
| 6116 | TestCompletionCallback callback; |
| 6117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6118 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6119 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6120 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6121 | |
| 6122 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6123 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6124 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6126 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6127 | ASSERT_TRUE(response); |
| 6128 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6129 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6130 | |
| 6131 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6132 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6133 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6134 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6136 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6137 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6138 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6139 | |
| 6140 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6141 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6142 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6143 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6144 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6145 | |
| 6146 | // The requests should have different IDs, since they each are using their own |
| 6147 | // separate stream. |
| 6148 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6150 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6151 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6155 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6156 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6157 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6158 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6159 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6160 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6161 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6162 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6163 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6164 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6165 | |
| 6166 | HttpRequestInfo request1; |
| 6167 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6168 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6169 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6170 | request1.traffic_annotation = |
| 6171 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6172 | |
| 6173 | HttpRequestInfo request2; |
| 6174 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6175 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6176 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6177 | request2.traffic_annotation = |
| 6178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6179 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6180 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6181 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6182 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6183 | spdy::SpdySerializedFrame conn_resp1( |
| 6184 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6185 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6186 | // Fetch https://www.example.org/ via HTTP. |
| 6187 | const char get1[] = |
| 6188 | "GET / HTTP/1.1\r\n" |
| 6189 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6190 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6191 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6192 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6193 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6194 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6195 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6196 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6197 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6198 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6199 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6200 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6201 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6202 | // Fetch https://www.example.org/2 via HTTP. |
| 6203 | const char get2[] = |
| 6204 | "GET /2 HTTP/1.1\r\n" |
| 6205 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6206 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6207 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6208 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6209 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6210 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6211 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6212 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6213 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6214 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6215 | |
| 6216 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6217 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6218 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | }; |
| 6220 | |
| 6221 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6222 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6223 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6224 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6225 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6226 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6227 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6228 | }; |
| 6229 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6230 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6231 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6232 | |
| 6233 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6234 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6235 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6236 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6237 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6238 | |
| 6239 | TestCompletionCallback callback; |
| 6240 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6241 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6242 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6243 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6245 | |
| 6246 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6247 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6248 | |
| 6249 | LoadTimingInfo load_timing_info; |
| 6250 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6251 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6252 | |
| 6253 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6254 | ASSERT_TRUE(response); |
| 6255 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6256 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6257 | |
| 6258 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6259 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6260 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6261 | trans.reset(); |
| 6262 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6263 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6264 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6265 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6267 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6268 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6269 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6270 | |
| 6271 | LoadTimingInfo load_timing_info2; |
| 6272 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6273 | TestLoadTimingReused(load_timing_info2); |
| 6274 | |
| 6275 | // The requests should have the same ID. |
| 6276 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6277 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6278 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6282 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6283 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6284 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6285 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6286 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6287 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6288 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6289 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6290 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6291 | |
| 6292 | HttpRequestInfo request1; |
| 6293 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6294 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6295 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6296 | request1.traffic_annotation = |
| 6297 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6298 | |
| 6299 | HttpRequestInfo request2; |
| 6300 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6301 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6302 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6303 | request2.traffic_annotation = |
| 6304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6305 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6306 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6307 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6308 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6309 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6310 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6311 | spdy::SpdySerializedFrame get_resp1( |
| 6312 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6313 | spdy::SpdySerializedFrame body1( |
| 6314 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6315 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6316 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6317 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6318 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6319 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6320 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6321 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6322 | spdy::SpdySerializedFrame get_resp2( |
| 6323 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 6324 | spdy::SpdySerializedFrame body2( |
| 6325 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6326 | |
| 6327 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6328 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6329 | }; |
| 6330 | |
| 6331 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6332 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6333 | CreateMockRead(body1, 2, ASYNC), |
| 6334 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6335 | CreateMockRead(body2, 5, ASYNC), |
| 6336 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6337 | }; |
| 6338 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6339 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6340 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6341 | |
| 6342 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6343 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6344 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6345 | |
| 6346 | TestCompletionCallback callback; |
| 6347 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6348 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6349 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6350 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6351 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6352 | |
| 6353 | LoadTimingInfo load_timing_info; |
| 6354 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6355 | TestLoadTimingNotReused(load_timing_info, |
| 6356 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6357 | |
| 6358 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6359 | ASSERT_TRUE(response); |
| 6360 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6361 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6362 | |
| 6363 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6364 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6365 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6366 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6367 | // Delete the first request, so the second one can reuse the socket. |
| 6368 | trans.reset(); |
| 6369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6370 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6371 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6372 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6373 | |
| 6374 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6375 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6376 | TestLoadTimingReused(load_timing_info2); |
| 6377 | |
| 6378 | // The requests should have the same ID. |
| 6379 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6381 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6382 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6383 | } |
| 6384 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6385 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6386 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6387 | // would break socket pool isolation. |
| 6388 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6389 | ProxyConfig proxy_config; |
| 6390 | proxy_config.set_auto_detect(true); |
| 6391 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6392 | |
| 6393 | CapturingProxyResolver capturing_proxy_resolver; |
| 6394 | session_deps_.proxy_resolution_service = |
| 6395 | std::make_unique<ProxyResolutionService>( |
| 6396 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6397 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6398 | std::make_unique<CapturingProxyResolverFactory>( |
| 6399 | &capturing_proxy_resolver), |
| 6400 | nullptr); |
| 6401 | |
| 6402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6403 | |
| 6404 | SpdyTestUtil spdy_util1; |
| 6405 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6406 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6407 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6408 | // fetch https://www.example.org/ via HTTP/2. |
| 6409 | const char kMyUrl[] = "https://www.example.org/"; |
| 6410 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6411 | spdy::SpdySerializedFrame wrapped_get( |
| 6412 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6413 | spdy::SpdySerializedFrame conn_resp( |
| 6414 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6415 | spdy::SpdySerializedFrame get_resp( |
| 6416 | spdy_util1.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6417 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6418 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6419 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6420 | spdy::SpdySerializedFrame wrapped_body( |
| 6421 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6422 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6423 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6424 | spdy::SpdySerializedFrame window_update_body( |
| 6425 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6426 | |
| 6427 | MockWrite spdy_writes1[] = { |
| 6428 | CreateMockWrite(connect, 0), |
| 6429 | CreateMockWrite(wrapped_get, 2), |
| 6430 | CreateMockWrite(window_update_get_resp, 6), |
| 6431 | CreateMockWrite(window_update_body, 7), |
| 6432 | }; |
| 6433 | |
| 6434 | MockRead spdy_reads1[] = { |
| 6435 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6436 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6437 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6438 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6439 | MockRead(ASYNC, 0, 8), |
| 6440 | }; |
| 6441 | |
| 6442 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6443 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6444 | |
| 6445 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6446 | // a new pipe. |
| 6447 | SpdyTestUtil spdy_util2; |
| 6448 | spdy::SpdySerializedFrame req( |
| 6449 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6450 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6451 | |
| 6452 | spdy::SpdySerializedFrame resp( |
| 6453 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6454 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6455 | MockRead spdy_reads2[] = { |
| 6456 | CreateMockRead(resp, 1), |
| 6457 | CreateMockRead(data, 2), |
| 6458 | MockRead(ASYNC, 0, 3), |
| 6459 | }; |
| 6460 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6461 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6462 | |
| 6463 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6464 | ssl.next_proto = kProtoHTTP2; |
| 6465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6466 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6467 | ssl2.next_proto = kProtoHTTP2; |
| 6468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6469 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6470 | ssl3.next_proto = kProtoHTTP2; |
| 6471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6472 | |
| 6473 | TestCompletionCallback callback; |
| 6474 | std::string response_data; |
| 6475 | |
| 6476 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6477 | capturing_proxy_resolver.set_proxy_server( |
| 6478 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6479 | HttpRequestInfo request1; |
| 6480 | request1.method = "GET"; |
| 6481 | request1.url = GURL("https://www.example.org/"); |
| 6482 | request1.traffic_annotation = |
| 6483 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6484 | |
| 6485 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6486 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6488 | |
| 6489 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6490 | base::RunLoop().RunUntilIdle(); |
| 6491 | // Now allow the read of the response to complete. |
| 6492 | spdy_data1.Resume(); |
| 6493 | rv = callback.WaitForResult(); |
| 6494 | EXPECT_THAT(rv, IsOk()); |
| 6495 | |
| 6496 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6497 | ASSERT_TRUE(response); |
| 6498 | ASSERT_TRUE(response->headers); |
| 6499 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6500 | |
| 6501 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6502 | EXPECT_EQ(kUploadData, response_data); |
| 6503 | RunUntilIdle(); |
| 6504 | |
| 6505 | // Make a direct HTTP/2 request to proxy:70. |
| 6506 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6507 | HttpRequestInfo request2; |
| 6508 | request2.method = "GET"; |
| 6509 | request2.url = GURL("https://proxy:70/"); |
| 6510 | request2.traffic_annotation = |
| 6511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6512 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6513 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6514 | NetLogWithSource())), |
| 6515 | IsOk()); |
| 6516 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6517 | } |
| 6518 | |
| 6519 | // Same as above, but reverse request order, since the code to check for an |
| 6520 | // existing session is different for tunnels and direct connections. |
| 6521 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6522 | // Configure against https proxy server "myproxy:80". |
| 6523 | ProxyConfig proxy_config; |
| 6524 | proxy_config.set_auto_detect(true); |
| 6525 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6526 | |
| 6527 | CapturingProxyResolver capturing_proxy_resolver; |
| 6528 | session_deps_.proxy_resolution_service = |
| 6529 | std::make_unique<ProxyResolutionService>( |
| 6530 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6531 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6532 | std::make_unique<CapturingProxyResolverFactory>( |
| 6533 | &capturing_proxy_resolver), |
| 6534 | nullptr); |
| 6535 | |
| 6536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6537 | // Fetch https://proxy:70/ via HTTP/2. |
| 6538 | SpdyTestUtil spdy_util1; |
| 6539 | spdy::SpdySerializedFrame req( |
| 6540 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6541 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6542 | |
| 6543 | spdy::SpdySerializedFrame resp( |
| 6544 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6545 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6546 | MockRead spdy_reads1[] = { |
| 6547 | CreateMockRead(resp, 1), |
| 6548 | CreateMockRead(data, 2), |
| 6549 | MockRead(ASYNC, 0, 3), |
| 6550 | }; |
| 6551 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6552 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6553 | |
| 6554 | SpdyTestUtil spdy_util2; |
| 6555 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6556 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6557 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6558 | // fetch https://www.example.org/ via HTTP/2. |
| 6559 | const char kMyUrl[] = "https://www.example.org/"; |
| 6560 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6561 | spdy::SpdySerializedFrame wrapped_get( |
| 6562 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6563 | spdy::SpdySerializedFrame conn_resp( |
| 6564 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6565 | spdy::SpdySerializedFrame get_resp( |
| 6566 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6567 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6568 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6569 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6570 | spdy::SpdySerializedFrame wrapped_body( |
| 6571 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6572 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6573 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6574 | spdy::SpdySerializedFrame window_update_body( |
| 6575 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6576 | |
| 6577 | MockWrite spdy_writes2[] = { |
| 6578 | CreateMockWrite(connect, 0), |
| 6579 | CreateMockWrite(wrapped_get, 2), |
| 6580 | CreateMockWrite(window_update_get_resp, 6), |
| 6581 | CreateMockWrite(window_update_body, 7), |
| 6582 | }; |
| 6583 | |
| 6584 | MockRead spdy_reads2[] = { |
| 6585 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6586 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6587 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6588 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6589 | MockRead(ASYNC, 0, 8), |
| 6590 | }; |
| 6591 | |
| 6592 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6593 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6594 | |
| 6595 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6596 | ssl.next_proto = kProtoHTTP2; |
| 6597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6598 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6599 | ssl2.next_proto = kProtoHTTP2; |
| 6600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6601 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6602 | ssl3.next_proto = kProtoHTTP2; |
| 6603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6604 | |
| 6605 | TestCompletionCallback callback; |
| 6606 | std::string response_data; |
| 6607 | |
| 6608 | // Make a direct HTTP/2 request to proxy:70. |
| 6609 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6610 | HttpRequestInfo request1; |
| 6611 | request1.method = "GET"; |
| 6612 | request1.url = GURL("https://proxy:70/"); |
| 6613 | request1.traffic_annotation = |
| 6614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6615 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6616 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6617 | NetLogWithSource())), |
| 6618 | IsOk()); |
| 6619 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6620 | RunUntilIdle(); |
| 6621 | |
| 6622 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6623 | capturing_proxy_resolver.set_proxy_server( |
| 6624 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6625 | HttpRequestInfo request2; |
| 6626 | request2.method = "GET"; |
| 6627 | request2.url = GURL("https://www.example.org/"); |
| 6628 | request2.traffic_annotation = |
| 6629 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6630 | |
| 6631 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6632 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6634 | |
| 6635 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6636 | base::RunLoop().RunUntilIdle(); |
| 6637 | // Now allow the read of the response to complete. |
| 6638 | spdy_data2.Resume(); |
| 6639 | rv = callback.WaitForResult(); |
| 6640 | EXPECT_THAT(rv, IsOk()); |
| 6641 | |
| 6642 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6643 | ASSERT_TRUE(response2); |
| 6644 | ASSERT_TRUE(response2->headers); |
| 6645 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6646 | |
| 6647 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6648 | EXPECT_EQ(kUploadData, response_data); |
| 6649 | } |
| 6650 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6651 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6652 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6653 | HttpRequestInfo request; |
| 6654 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6655 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6656 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6657 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6658 | request.traffic_annotation = |
| 6659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6660 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6661 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6662 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6663 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6664 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6665 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6666 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6667 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6668 | // Since we have proxy, should use full url |
| 6669 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6670 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6671 | "Host: www.example.org\r\n" |
| 6672 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6674 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6675 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6676 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6677 | "Host: www.example.org\r\n" |
| 6678 | "Proxy-Connection: keep-alive\r\n" |
| 6679 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6680 | }; |
| 6681 | |
| 6682 | // The proxy responds to the GET with a 407, using a persistent |
| 6683 | // connection. |
| 6684 | MockRead data_reads1[] = { |
| 6685 | // No credentials. |
| 6686 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6687 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6688 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6689 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6690 | |
| 6691 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6692 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6693 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6695 | }; |
| 6696 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6697 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6699 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6700 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6702 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6706 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6708 | |
| 6709 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6710 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6711 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6712 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6713 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6714 | TestLoadTimingNotReused(load_timing_info, |
| 6715 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6717 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6718 | ASSERT_TRUE(response); |
| 6719 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6720 | EXPECT_EQ(407, response->headers->response_code()); |
| 6721 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6722 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6724 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6726 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6728 | |
| 6729 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6730 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6731 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6732 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6733 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6734 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6735 | TestLoadTimingReused(load_timing_info); |
| 6736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6737 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6738 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6739 | |
| 6740 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6741 | EXPECT_EQ(200, response->headers->response_code()); |
| 6742 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6743 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6744 | |
| 6745 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6746 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6747 | } |
| 6748 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6749 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6750 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6751 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6753 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6754 | request.traffic_annotation = |
| 6755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6756 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6757 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6758 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6759 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6761 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6762 | // Since we have proxy, should try to establish tunnel. |
| 6763 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6764 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6765 | "Host: www.example.org:443\r\n" |
| 6766 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6767 | }; |
| 6768 | |
| 6769 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6770 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6771 | // No response body because the test stops reading here. |
| 6772 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6773 | }; |
| 6774 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6775 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6776 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6778 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6780 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6781 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6782 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6784 | |
| 6785 | rv = callback.WaitForResult(); |
| 6786 | EXPECT_EQ(expected_status, rv); |
| 6787 | } |
| 6788 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6789 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6790 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6791 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6792 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6793 | } |
| 6794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6795 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6796 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6797 | } |
| 6798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6799 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6800 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6801 | } |
| 6802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6803 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6804 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6805 | } |
| 6806 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6807 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6808 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6809 | } |
| 6810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6811 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6812 | ConnectStatusHelper( |
| 6813 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6814 | } |
| 6815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6816 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6817 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6818 | } |
| 6819 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6820 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6821 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6822 | } |
| 6823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6824 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6825 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6826 | } |
| 6827 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6828 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6829 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6830 | } |
| 6831 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6832 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6833 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6834 | } |
| 6835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6836 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6837 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6838 | } |
| 6839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6841 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6842 | } |
| 6843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6844 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6845 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6846 | } |
| 6847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6848 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6849 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6850 | } |
| 6851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6852 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6853 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6854 | } |
| 6855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6857 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6858 | } |
| 6859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6861 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6862 | } |
| 6863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6865 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6866 | } |
| 6867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6868 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6869 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6870 | } |
| 6871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6872 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6873 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6874 | } |
| 6875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6876 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6877 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6878 | } |
| 6879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6880 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6881 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6882 | } |
| 6883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6885 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6886 | } |
| 6887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6889 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6890 | } |
| 6891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6893 | ConnectStatusHelperWithExpectedStatus( |
| 6894 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6895 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6896 | } |
| 6897 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6898 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6899 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6900 | } |
| 6901 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6902 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6903 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6904 | } |
| 6905 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6906 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6907 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6908 | } |
| 6909 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6910 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6911 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6912 | } |
| 6913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6914 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6915 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6916 | } |
| 6917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6919 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6920 | } |
| 6921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6923 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6924 | } |
| 6925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6927 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6928 | } |
| 6929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6931 | ConnectStatusHelper( |
| 6932 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6933 | } |
| 6934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6935 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6936 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6937 | } |
| 6938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6939 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6940 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6941 | } |
| 6942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6943 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6944 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6945 | } |
| 6946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6947 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6948 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6949 | } |
| 6950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6951 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6952 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6953 | } |
| 6954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6956 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6961 | } |
| 6962 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6963 | // Test the flow when both the proxy server AND origin server require |
| 6964 | // authentication. Again, this uses basic auth for both since that is |
| 6965 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6966 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6967 | HttpRequestInfo request; |
| 6968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6969 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6970 | request.traffic_annotation = |
| 6971 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6972 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6973 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6974 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6975 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6978 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6979 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6980 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6981 | MockWrite( |
| 6982 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6983 | "Host: www.example.org\r\n" |
| 6984 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6985 | }; |
| 6986 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6987 | MockRead data_reads1[] = { |
| 6988 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6989 | // Give a couple authenticate options (only the middle one is actually |
| 6990 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6991 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6992 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6993 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6994 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6995 | // Large content-length -- won't matter, as connection will be reset. |
| 6996 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6997 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6998 | }; |
| 6999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7000 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7001 | // request we should be issuing -- the final header line contains the |
| 7002 | // proxy's credentials. |
| 7003 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7004 | MockWrite( |
| 7005 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7006 | "Host: www.example.org\r\n" |
| 7007 | "Proxy-Connection: keep-alive\r\n" |
| 7008 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7009 | }; |
| 7010 | |
| 7011 | // Now the proxy server lets the request pass through to origin server. |
| 7012 | // The origin server responds with a 401. |
| 7013 | MockRead data_reads2[] = { |
| 7014 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7015 | // Note: We are using the same realm-name as the proxy server. This is |
| 7016 | // completely valid, as realms are unique across hosts. |
| 7017 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7019 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7020 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7021 | }; |
| 7022 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7023 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7024 | // the credentials for both the proxy and origin server. |
| 7025 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7026 | MockWrite( |
| 7027 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7028 | "Host: www.example.org\r\n" |
| 7029 | "Proxy-Connection: keep-alive\r\n" |
| 7030 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7031 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7032 | }; |
| 7033 | |
| 7034 | // Lastly we get the desired content. |
| 7035 | MockRead data_reads3[] = { |
| 7036 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7037 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7038 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7039 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7040 | }; |
| 7041 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7042 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7043 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7044 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7045 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7046 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7047 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7049 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7050 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7051 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7053 | |
| 7054 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7055 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7057 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7058 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7059 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7061 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7063 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7065 | |
| 7066 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7067 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7069 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7070 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7071 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7073 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7075 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7076 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7078 | |
| 7079 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7082 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7083 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7084 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7085 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7086 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7087 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7088 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7089 | // authorization headers. |
| 7090 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7091 | // The NTLM authentication unit tests are based on known test data from the |
| 7092 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7093 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7094 | // for the implementation and testing of the protocol. |
| 7095 | // |
| 7096 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7097 | |
| 7098 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7099 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7100 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7101 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7102 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7103 | request.traffic_annotation = |
| 7104 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7105 | |
| 7106 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7107 | // to other auth schemes. |
| 7108 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7109 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7110 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7111 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7113 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7114 | // Generate the NTLM messages based on known test data. |
| 7115 | std::string negotiate_msg; |
| 7116 | std::string challenge_msg; |
| 7117 | std::string authenticate_msg; |
| 7118 | base::Base64Encode( |
| 7119 | base::StringPiece( |
| 7120 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7121 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7122 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7123 | base::Base64Encode( |
| 7124 | base::StringPiece( |
| 7125 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7126 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7127 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7128 | base::Base64Encode( |
| 7129 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7130 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7131 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7132 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7133 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7134 | &authenticate_msg); |
| 7135 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7136 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7137 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7138 | "Host: server\r\n" |
| 7139 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7140 | }; |
| 7141 | |
| 7142 | MockRead data_reads1[] = { |
| 7143 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7144 | // Negotiate and NTLM are often requested together. However, we only want |
| 7145 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7146 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7147 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7148 | MockRead("Connection: close\r\n"), |
| 7149 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7150 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7151 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7152 | }; |
| 7153 | |
| 7154 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7155 | // After restarting with a null identity, this is the |
| 7156 | // request we should be issuing -- the final header line contains a Type |
| 7157 | // 1 message. |
| 7158 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7159 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7160 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7161 | "Authorization: NTLM "), |
| 7162 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7164 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7165 | // (using correct credentials). The second request continues on the |
| 7166 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7167 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7168 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7169 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7170 | "Authorization: NTLM "), |
| 7171 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7172 | }; |
| 7173 | |
| 7174 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7175 | // The origin server responds with a Type 2 message. |
| 7176 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7177 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7178 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7179 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7180 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7181 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7182 | // Lastly we get the desired content. |
| 7183 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7184 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7185 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7186 | }; |
| 7187 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7188 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7189 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7190 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7191 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7192 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7193 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7195 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7198 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7200 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7202 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7204 | |
| 7205 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7208 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7210 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7211 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7212 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7214 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7215 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7216 | rv = trans.RestartWithAuth( |
| 7217 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7218 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7220 | |
| 7221 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7222 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7224 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7226 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7227 | ASSERT_TRUE(response); |
| 7228 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7230 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7232 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7234 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7235 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7238 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7239 | ASSERT_TRUE(response); |
| 7240 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7241 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7242 | |
| 7243 | std::string response_data; |
| 7244 | rv = ReadTransaction(&trans, &response_data); |
| 7245 | EXPECT_THAT(rv, IsOk()); |
| 7246 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7247 | |
| 7248 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7249 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7250 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7251 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7252 | } |
| 7253 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7254 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7255 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7256 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7257 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7258 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7259 | request.traffic_annotation = |
| 7260 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7261 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7262 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7263 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7264 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7265 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7266 | // Generate the NTLM messages based on known test data. |
| 7267 | std::string negotiate_msg; |
| 7268 | std::string challenge_msg; |
| 7269 | std::string authenticate_msg; |
| 7270 | base::Base64Encode( |
| 7271 | base::StringPiece( |
| 7272 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7273 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7274 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7275 | base::Base64Encode( |
| 7276 | base::StringPiece( |
| 7277 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7278 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7279 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7280 | base::Base64Encode( |
| 7281 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7282 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7283 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7284 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7285 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7286 | &authenticate_msg); |
| 7287 | |
| 7288 | // The authenticate message when |kWrongPassword| is sent. |
| 7289 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7290 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7291 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7292 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7293 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7294 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7295 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7296 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7297 | // Sanity check that it's the same length as the correct authenticate message |
| 7298 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7299 | ASSERT_EQ(authenticate_msg.length(), |
| 7300 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7301 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7302 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7303 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7304 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7305 | "Host: server\r\n" |
| 7306 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7307 | }; |
| 7308 | |
| 7309 | MockRead data_reads1[] = { |
| 7310 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7311 | // Negotiate and NTLM are often requested together. However, we only want |
| 7312 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7313 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7314 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7315 | MockRead("Connection: close\r\n"), |
| 7316 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7317 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7318 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7319 | }; |
| 7320 | |
| 7321 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7322 | // After restarting with a null identity, this is the |
| 7323 | // request we should be issuing -- the final header line contains a Type |
| 7324 | // 1 message. |
| 7325 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7326 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7327 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7328 | "Authorization: NTLM "), |
| 7329 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7331 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7332 | // (using incorrect credentials). The second request continues on the |
| 7333 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7334 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7335 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7336 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7337 | "Authorization: NTLM "), |
| 7338 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7342 | // The origin server responds with a Type 2 message. |
| 7343 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7344 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7345 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7346 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7347 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7348 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7349 | // Wrong password. |
| 7350 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7351 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7352 | MockRead("Content-Length: 42\r\n"), |
| 7353 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7354 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7355 | }; |
| 7356 | |
| 7357 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7358 | // After restarting with a null identity, this is the |
| 7359 | // request we should be issuing -- the final header line contains a Type |
| 7360 | // 1 message. |
| 7361 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7362 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7363 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7364 | "Authorization: NTLM "), |
| 7365 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7367 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7368 | // (the credentials for the origin server). The second request continues |
| 7369 | // on the same connection. |
| 7370 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7371 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7372 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7373 | "Authorization: NTLM "), |
| 7374 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7375 | }; |
| 7376 | |
| 7377 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7378 | // The origin server responds with a Type 2 message. |
| 7379 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7380 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7381 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7382 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7383 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7384 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7385 | // Lastly we get the desired content. |
| 7386 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7387 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7388 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7389 | }; |
| 7390 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7391 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7392 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7393 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7394 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7395 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7396 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7397 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7398 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7400 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7402 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7405 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7409 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7411 | |
| 7412 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7415 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7417 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7418 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7419 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7421 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7422 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7423 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7424 | rv = trans.RestartWithAuth( |
| 7425 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7426 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7428 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7429 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7430 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7432 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7433 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7434 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7436 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7437 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7438 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7440 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7441 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7442 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7444 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7445 | |
| 7446 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7447 | rv = trans.RestartWithAuth( |
| 7448 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7449 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7451 | |
| 7452 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7453 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7455 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7457 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7458 | |
| 7459 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7460 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7462 | |
| 7463 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7464 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7466 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7467 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7468 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7469 | |
| 7470 | std::string response_data; |
| 7471 | rv = ReadTransaction(&trans, &response_data); |
| 7472 | EXPECT_THAT(rv, IsOk()); |
| 7473 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7474 | |
| 7475 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7476 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7477 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7478 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7479 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7480 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7481 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7482 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7483 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7484 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7485 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7486 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7487 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7488 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7489 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7490 | |
| 7491 | HttpRequestInfo request; |
| 7492 | request.method = "GET"; |
| 7493 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7494 | request.traffic_annotation = |
| 7495 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7496 | |
| 7497 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7498 | spdy::SpdyHeaderBlock request_headers0( |
| 7499 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7500 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7501 | 1, std::move(request_headers0), LOWEST, true)); |
| 7502 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7503 | spdy::SpdyHeaderBlock response_headers0; |
| 7504 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7505 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7506 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7507 | 1, std::move(response_headers0), true)); |
| 7508 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7509 | // Stream 1 is closed. |
| 7510 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7511 | |
| 7512 | // Generate the NTLM messages based on known test data. |
| 7513 | std::string negotiate_msg; |
| 7514 | std::string challenge_msg; |
| 7515 | std::string authenticate_msg; |
| 7516 | base::Base64Encode( |
| 7517 | base::StringPiece( |
| 7518 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7519 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7520 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7521 | base::Base64Encode( |
| 7522 | base::StringPiece( |
| 7523 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7524 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7525 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7526 | base::Base64Encode( |
| 7527 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7528 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7529 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7530 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7531 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7532 | &authenticate_msg); |
| 7533 | |
| 7534 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7535 | spdy::SpdyHeaderBlock request_headers1( |
| 7536 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7537 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7538 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7539 | 3, std::move(request_headers1), LOWEST, true)); |
| 7540 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7541 | spdy::SpdySerializedFrame rst( |
| 7542 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7543 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7544 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7545 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7546 | |
| 7547 | // Retry yet again using HTTP/1.1. |
| 7548 | MockWrite writes1[] = { |
| 7549 | // After restarting with a null identity, this is the |
| 7550 | // request we should be issuing -- the final header line contains a Type |
| 7551 | // 1 message. |
| 7552 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7553 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7554 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7555 | "Authorization: NTLM "), |
| 7556 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7557 | |
| 7558 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7559 | // (the credentials for the origin server). The second request continues |
| 7560 | // on the same connection. |
| 7561 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7562 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7563 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7564 | "Authorization: NTLM "), |
| 7565 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7566 | }; |
| 7567 | |
| 7568 | MockRead reads1[] = { |
| 7569 | // The origin server responds with a Type 2 message. |
| 7570 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7571 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7572 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7573 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7574 | MockRead("You are not authorized to view this page\r\n"), |
| 7575 | |
| 7576 | // Lastly we get the desired content. |
| 7577 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7578 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7579 | 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] | 7580 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7581 | SequencedSocketData data0(reads0, writes0); |
| 7582 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7583 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7584 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7585 | |
| 7586 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7587 | ssl0.next_proto = kProtoHTTP2; |
| 7588 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7589 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7591 | |
| 7592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7593 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7594 | |
| 7595 | TestCompletionCallback callback1; |
| 7596 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7598 | |
| 7599 | rv = callback1.WaitForResult(); |
| 7600 | EXPECT_THAT(rv, IsOk()); |
| 7601 | |
| 7602 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7603 | |
| 7604 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7605 | ASSERT_TRUE(response); |
| 7606 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7607 | |
| 7608 | TestCompletionCallback callback2; |
| 7609 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7610 | rv = trans.RestartWithAuth( |
| 7611 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7612 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7614 | |
| 7615 | rv = callback2.WaitForResult(); |
| 7616 | EXPECT_THAT(rv, IsOk()); |
| 7617 | |
| 7618 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7619 | |
| 7620 | response = trans.GetResponseInfo(); |
| 7621 | ASSERT_TRUE(response); |
| 7622 | EXPECT_FALSE(response->auth_challenge); |
| 7623 | |
| 7624 | TestCompletionCallback callback3; |
| 7625 | |
| 7626 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7627 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7628 | |
| 7629 | rv = callback3.WaitForResult(); |
| 7630 | EXPECT_THAT(rv, IsOk()); |
| 7631 | |
| 7632 | response = trans.GetResponseInfo(); |
| 7633 | ASSERT_TRUE(response); |
| 7634 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7635 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7636 | |
| 7637 | std::string response_data; |
| 7638 | rv = ReadTransaction(&trans, &response_data); |
| 7639 | EXPECT_THAT(rv, IsOk()); |
| 7640 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7641 | |
| 7642 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7643 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7644 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7645 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7646 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7647 | |
| 7648 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7649 | // do no retry forever checking for TLS version interference. This is a |
| 7650 | // regression test for https://crbug.com/823387. |
| 7651 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7652 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7653 | // https://origin/. |
| 7654 | session_deps_.proxy_resolution_service = |
| 7655 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7656 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7657 | |
| 7658 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7659 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7660 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7661 | |
| 7662 | HttpRequestInfo request; |
| 7663 | request.method = "GET"; |
| 7664 | request.url = GURL("https://origin/"); |
| 7665 | request.traffic_annotation = |
| 7666 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7667 | |
| 7668 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7669 | // to other auth schemes. |
| 7670 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7671 | |
| 7672 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7673 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7675 | |
| 7676 | // Generate the NTLM messages based on known test data. |
| 7677 | std::string negotiate_msg; |
| 7678 | std::string challenge_msg; |
| 7679 | std::string authenticate_msg; |
| 7680 | base::Base64Encode( |
| 7681 | base::StringPiece( |
| 7682 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7683 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7684 | &negotiate_msg); |
| 7685 | base::Base64Encode( |
| 7686 | base::StringPiece( |
| 7687 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7688 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7689 | &challenge_msg); |
| 7690 | base::Base64Encode( |
| 7691 | base::StringPiece( |
| 7692 | reinterpret_cast<const char*>( |
| 7693 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7694 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7695 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7696 | &authenticate_msg); |
| 7697 | |
| 7698 | MockWrite data_writes[] = { |
| 7699 | // The initial CONNECT request. |
| 7700 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7701 | "Host: origin:443\r\n" |
| 7702 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7703 | |
| 7704 | // After restarting with an identity. |
| 7705 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7706 | "Host: origin:443\r\n" |
| 7707 | "Proxy-Connection: keep-alive\r\n" |
| 7708 | "Proxy-Authorization: NTLM "), |
| 7709 | MockWrite(negotiate_msg.c_str()), |
| 7710 | // End headers. |
| 7711 | MockWrite("\r\n\r\n"), |
| 7712 | |
| 7713 | // The second restart. |
| 7714 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7715 | "Host: origin:443\r\n" |
| 7716 | "Proxy-Connection: keep-alive\r\n" |
| 7717 | "Proxy-Authorization: NTLM "), |
| 7718 | MockWrite(authenticate_msg.c_str()), |
| 7719 | // End headers. |
| 7720 | MockWrite("\r\n\r\n"), |
| 7721 | }; |
| 7722 | |
| 7723 | MockRead data_reads[] = { |
| 7724 | // The initial NTLM response. |
| 7725 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7726 | "Content-Length: 0\r\n" |
| 7727 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7728 | |
| 7729 | // The NTLM challenge message. |
| 7730 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7731 | "Content-Length: 0\r\n" |
| 7732 | "Proxy-Authenticate: NTLM "), |
| 7733 | MockRead(challenge_msg.c_str()), |
| 7734 | // End headers. |
| 7735 | MockRead("\r\n\r\n"), |
| 7736 | |
| 7737 | // Finally the tunnel is established. |
| 7738 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7739 | }; |
| 7740 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7741 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7742 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7743 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7744 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7745 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7748 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7750 | |
| 7751 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7752 | // request. |
| 7753 | TestCompletionCallback callback; |
| 7754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7755 | int rv = callback.GetResult( |
| 7756 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7757 | |
| 7758 | EXPECT_THAT(rv, IsOk()); |
| 7759 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7760 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7761 | ASSERT_TRUE(response); |
| 7762 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7763 | |
| 7764 | // Configure credentials. The proxy responds with the challenge message. |
| 7765 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7766 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7767 | callback.callback())); |
| 7768 | EXPECT_THAT(rv, IsOk()); |
| 7769 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7770 | response = trans.GetResponseInfo(); |
| 7771 | ASSERT_TRUE(response); |
| 7772 | EXPECT_FALSE(response->auth_challenge); |
| 7773 | |
| 7774 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7775 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7776 | // restart the process. The proxy responds with another NTLM authentiation |
| 7777 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7778 | rv = callback.GetResult( |
| 7779 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7780 | EXPECT_THAT(rv, IsOk()); |
| 7781 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7782 | response = trans.GetResponseInfo(); |
| 7783 | ASSERT_TRUE(response); |
| 7784 | EXPECT_FALSE(response->auth_challenge); |
| 7785 | |
| 7786 | // The proxy responds with the NTLM challenge message. |
| 7787 | rv = callback.GetResult( |
| 7788 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7789 | EXPECT_THAT(rv, IsOk()); |
| 7790 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7791 | response = trans.GetResponseInfo(); |
| 7792 | ASSERT_TRUE(response); |
| 7793 | EXPECT_FALSE(response->auth_challenge); |
| 7794 | |
| 7795 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7796 | // handshake resets again. We should not retry again. |
| 7797 | rv = callback.GetResult( |
| 7798 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7799 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7800 | } |
| 7801 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7802 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7803 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7804 | // Test reading a server response which has only headers, and no body. |
| 7805 | // After some maximum number of bytes is consumed, the transaction should |
| 7806 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7807 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7808 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7810 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7811 | request.traffic_annotation = |
| 7812 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7816 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7817 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7818 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7819 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7820 | |
| 7821 | MockRead data_reads[] = { |
| 7822 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7823 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7824 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7826 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7827 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7830 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7831 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7832 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7834 | |
| 7835 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7836 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7837 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7838 | |
| 7839 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7840 | // establish tunnel. |
| 7841 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7842 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7843 | HttpRequestInfo request; |
| 7844 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7845 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7846 | request.traffic_annotation = |
| 7847 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7848 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7849 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7850 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7851 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7852 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7854 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7855 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7856 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7857 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7858 | // Since we have proxy, should try to establish tunnel. |
| 7859 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7860 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7861 | "Host: www.example.org:443\r\n" |
| 7862 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7863 | }; |
| 7864 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7865 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7866 | // connection. Usually a proxy would return 501 (not implemented), |
| 7867 | // or 200 (tunnel established). |
| 7868 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7869 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7870 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7871 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7872 | }; |
| 7873 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7874 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7875 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7877 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7879 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7881 | |
| 7882 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7883 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7884 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7885 | // Empty the current queue. This is necessary because idle sockets are |
| 7886 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7887 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7888 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7889 | // We now check to make sure the TCPClientSocket was not added back to |
| 7890 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7891 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7892 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7893 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7894 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7895 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7896 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7897 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7898 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7899 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7900 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7902 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7903 | request.traffic_annotation = |
| 7904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7908 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7909 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7910 | MockRead data_reads[] = { |
| 7911 | // A part of the response body is received with the response headers. |
| 7912 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7913 | // The rest of the response body is received in two parts. |
| 7914 | MockRead("lo"), |
| 7915 | MockRead(" world"), |
| 7916 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7917 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7918 | }; |
| 7919 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7920 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7921 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7923 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7924 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7925 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7927 | |
| 7928 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7929 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7931 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7932 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7933 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7934 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7935 | std::string status_line = response->headers->GetStatusLine(); |
| 7936 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7937 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7938 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7939 | |
| 7940 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7941 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7942 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7943 | EXPECT_EQ("hello world", response_data); |
| 7944 | |
| 7945 | // Empty the current queue. This is necessary because idle sockets are |
| 7946 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7947 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7948 | |
| 7949 | // 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] | 7950 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7951 | } |
| 7952 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7953 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7954 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7955 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7956 | HttpRequestInfo request; |
| 7957 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7958 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7959 | request.traffic_annotation = |
| 7960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7961 | |
| 7962 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7963 | MockWrite( |
| 7964 | "GET / HTTP/1.1\r\n" |
| 7965 | "Host: www.example.org\r\n" |
| 7966 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7967 | }; |
| 7968 | |
| 7969 | MockRead data_reads[] = { |
| 7970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7971 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7972 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7973 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7974 | }; |
| 7975 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7976 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7979 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7982 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7983 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7985 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7986 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7987 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7988 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7990 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7992 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7993 | ASSERT_TRUE(response); |
| 7994 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7995 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7996 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7997 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7998 | |
| 7999 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8000 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8001 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8002 | EXPECT_EQ("hello world", response_data); |
| 8003 | |
| 8004 | // Empty the current queue. This is necessary because idle sockets are |
| 8005 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8006 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8007 | |
| 8008 | // We now check to make sure the socket was added back to the pool. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8009 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8013 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8014 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8015 | HttpRequestInfo request; |
| 8016 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8017 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8018 | request.traffic_annotation = |
| 8019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8020 | |
| 8021 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8022 | MockWrite( |
| 8023 | "GET / HTTP/1.1\r\n" |
| 8024 | "Host: www.example.org\r\n" |
| 8025 | "Connection: keep-alive\r\n\r\n"), |
| 8026 | MockWrite( |
| 8027 | "GET / HTTP/1.1\r\n" |
| 8028 | "Host: www.example.org\r\n" |
| 8029 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8030 | }; |
| 8031 | |
| 8032 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8033 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8034 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8035 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8036 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8037 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8040 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8041 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8042 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8043 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8044 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8046 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8047 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8048 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8049 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8050 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8051 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8052 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8053 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8055 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8056 | |
| 8057 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8058 | ASSERT_TRUE(response); |
| 8059 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8060 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8061 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8062 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8063 | |
| 8064 | std::string response_data; |
| 8065 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8066 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8067 | EXPECT_EQ("hello world", response_data); |
| 8068 | |
| 8069 | // Empty the current queue. This is necessary because idle sockets are |
| 8070 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8071 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8072 | |
| 8073 | // We now check to make sure the socket was added back to the pool. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8074 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8075 | |
| 8076 | // Now start the second transaction, which should reuse the previous socket. |
| 8077 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8078 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8079 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8081 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8082 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8084 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8085 | |
| 8086 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8087 | ASSERT_TRUE(response); |
| 8088 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8089 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8090 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8091 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8092 | |
| 8093 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8094 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8095 | EXPECT_EQ("hello world", response_data); |
| 8096 | |
| 8097 | // Empty the current queue. This is necessary because idle sockets are |
| 8098 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8099 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8100 | |
| 8101 | // We now check to make sure the socket was added back to the pool. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8102 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8103 | } |
| 8104 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8105 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8106 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8107 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8108 | HttpRequestInfo request; |
| 8109 | request.method = "GET"; |
| 8110 | request.url = GURL("http://www.example.org/"); |
| 8111 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8112 | request.traffic_annotation = |
| 8113 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8114 | |
| 8115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8116 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8117 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8118 | |
| 8119 | MockRead data_reads[] = { |
| 8120 | // A part of the response body is received with the response headers. |
| 8121 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8122 | // The rest of the response body is received in two parts. |
| 8123 | MockRead("lo"), MockRead(" world"), |
| 8124 | MockRead("junk"), // Should not be read!! |
| 8125 | MockRead(SYNCHRONOUS, OK), |
| 8126 | }; |
| 8127 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8128 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8129 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8130 | |
| 8131 | TestCompletionCallback callback; |
| 8132 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8133 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8135 | |
| 8136 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8138 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8139 | ASSERT_TRUE(response); |
| 8140 | EXPECT_TRUE(response->headers); |
| 8141 | std::string status_line = response->headers->GetStatusLine(); |
| 8142 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8143 | |
| 8144 | // Make memory critical notification and ensure the transaction still has been |
| 8145 | // operating right. |
| 8146 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8147 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8148 | base::RunLoop().RunUntilIdle(); |
| 8149 | |
| 8150 | // Socket should not be flushed as long as it is not idle. |
| 8151 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8152 | |
| 8153 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8154 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8155 | EXPECT_THAT(rv, IsOk()); |
| 8156 | EXPECT_EQ("hello world", response_data); |
| 8157 | |
| 8158 | // Empty the current queue. This is necessary because idle sockets are |
| 8159 | // added to the connection pool asynchronously with a PostTask. |
| 8160 | base::RunLoop().RunUntilIdle(); |
| 8161 | |
| 8162 | // We now check to make sure the socket was added back to the pool. |
| 8163 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8164 | |
| 8165 | // Idle sockets should be flushed now. |
| 8166 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8167 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8168 | base::RunLoop().RunUntilIdle(); |
| 8169 | |
| 8170 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8171 | } |
| 8172 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8173 | // Disable idle socket closing on memory pressure. |
| 8174 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8175 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8176 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8177 | HttpRequestInfo request; |
| 8178 | request.method = "GET"; |
| 8179 | request.url = GURL("http://www.example.org/"); |
| 8180 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8181 | request.traffic_annotation = |
| 8182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8183 | |
| 8184 | // Disable idle socket closing on memory pressure. |
| 8185 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8187 | |
| 8188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8189 | |
| 8190 | MockRead data_reads[] = { |
| 8191 | // A part of the response body is received with the response headers. |
| 8192 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8193 | // The rest of the response body is received in two parts. |
| 8194 | MockRead("lo"), MockRead(" world"), |
| 8195 | MockRead("junk"), // Should not be read!! |
| 8196 | MockRead(SYNCHRONOUS, OK), |
| 8197 | }; |
| 8198 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8199 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8201 | |
| 8202 | TestCompletionCallback callback; |
| 8203 | |
| 8204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8206 | |
| 8207 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8208 | |
| 8209 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8210 | ASSERT_TRUE(response); |
| 8211 | EXPECT_TRUE(response->headers); |
| 8212 | std::string status_line = response->headers->GetStatusLine(); |
| 8213 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8214 | |
| 8215 | // Make memory critical notification and ensure the transaction still has been |
| 8216 | // operating right. |
| 8217 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8218 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8219 | base::RunLoop().RunUntilIdle(); |
| 8220 | |
| 8221 | // Socket should not be flushed as long as it is not idle. |
| 8222 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8223 | |
| 8224 | std::string response_data; |
| 8225 | rv = ReadTransaction(&trans, &response_data); |
| 8226 | EXPECT_THAT(rv, IsOk()); |
| 8227 | EXPECT_EQ("hello world", response_data); |
| 8228 | |
| 8229 | // Empty the current queue. This is necessary because idle sockets are |
| 8230 | // added to the connection pool asynchronously with a PostTask. |
| 8231 | base::RunLoop().RunUntilIdle(); |
| 8232 | |
| 8233 | // We now check to make sure the socket was added back to the pool. |
| 8234 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8235 | |
| 8236 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8237 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8238 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8239 | base::RunLoop().RunUntilIdle(); |
| 8240 | |
| 8241 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8242 | |
| 8243 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8244 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8245 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8246 | base::RunLoop().RunUntilIdle(); |
| 8247 | |
| 8248 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8249 | } |
| 8250 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8251 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8252 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8253 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8254 | HttpRequestInfo request; |
| 8255 | request.method = "GET"; |
| 8256 | request.url = GURL("https://www.example.org/"); |
| 8257 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8258 | request.traffic_annotation = |
| 8259 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8260 | |
| 8261 | MockWrite data_writes[] = { |
| 8262 | MockWrite("GET / HTTP/1.1\r\n" |
| 8263 | "Host: www.example.org\r\n" |
| 8264 | "Connection: keep-alive\r\n\r\n"), |
| 8265 | }; |
| 8266 | |
| 8267 | MockRead data_reads[] = { |
| 8268 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8269 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8270 | |
| 8271 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8273 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8274 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8275 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8276 | |
| 8277 | TestCompletionCallback callback; |
| 8278 | |
| 8279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8281 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8282 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8283 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8284 | |
| 8285 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8287 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8288 | ASSERT_TRUE(response); |
| 8289 | ASSERT_TRUE(response->headers); |
| 8290 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8291 | |
| 8292 | // Make memory critical notification and ensure the transaction still has been |
| 8293 | // operating right. |
| 8294 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8295 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8296 | base::RunLoop().RunUntilIdle(); |
| 8297 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8298 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8299 | |
| 8300 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8301 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8302 | EXPECT_THAT(rv, IsOk()); |
| 8303 | EXPECT_EQ("hello world", response_data); |
| 8304 | |
| 8305 | // Empty the current queue. This is necessary because idle sockets are |
| 8306 | // added to the connection pool asynchronously with a PostTask. |
| 8307 | base::RunLoop().RunUntilIdle(); |
| 8308 | |
| 8309 | // We now check to make sure the socket was added back to the pool. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8310 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8311 | |
| 8312 | // Make memory notification once again and ensure idle socket is closed. |
| 8313 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8314 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8315 | base::RunLoop().RunUntilIdle(); |
| 8316 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8317 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8318 | } |
| 8319 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8320 | // Make sure that we recycle a socket after a zero-length response. |
| 8321 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8322 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8323 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8324 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8325 | request.url = GURL( |
| 8326 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8327 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8328 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8329 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8330 | request.traffic_annotation = |
| 8331 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8332 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8334 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8335 | MockRead data_reads[] = { |
| 8336 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8337 | "Content-Length: 0\r\n" |
| 8338 | "Content-Type: text/html\r\n\r\n"), |
| 8339 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8340 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8341 | }; |
| 8342 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8343 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8344 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8345 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8346 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8347 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8348 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8350 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8351 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8352 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8354 | |
| 8355 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8356 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8359 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8360 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8361 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8362 | std::string status_line = response->headers->GetStatusLine(); |
| 8363 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8364 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8365 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8366 | |
| 8367 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8368 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8370 | EXPECT_EQ("", response_data); |
| 8371 | |
| 8372 | // Empty the current queue. This is necessary because idle sockets are |
| 8373 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8374 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8375 | |
| 8376 | // 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] | 8377 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8378 | } |
| 8379 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8380 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8381 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8382 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8383 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8384 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8385 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8386 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8387 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8388 | // after use. |
| 8389 | request[0].method = "GET"; |
| 8390 | request[0].url = GURL("http://www.google.com/"); |
| 8391 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8392 | request[0].traffic_annotation = |
| 8393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8394 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8395 | // transaction 1. The first attempts fails when writing the POST data. |
| 8396 | // This causes the transaction to retry with a new socket. The second |
| 8397 | // attempt succeeds. |
| 8398 | request[1].method = "POST"; |
| 8399 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8400 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8401 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8402 | request[1].traffic_annotation = |
| 8403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8406 | |
| 8407 | // The first socket is used for transaction 1 and the first attempt of |
| 8408 | // transaction 2. |
| 8409 | |
| 8410 | // The response of transaction 1. |
| 8411 | MockRead data_reads1[] = { |
| 8412 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8413 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8414 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8415 | }; |
| 8416 | // The mock write results of transaction 1 and the first attempt of |
| 8417 | // transaction 2. |
| 8418 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8419 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8420 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8421 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8422 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8423 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8424 | |
| 8425 | // The second socket is used for the second attempt of transaction 2. |
| 8426 | |
| 8427 | // The response of transaction 2. |
| 8428 | MockRead data_reads2[] = { |
| 8429 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8430 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8432 | }; |
| 8433 | // The mock write results of the second attempt of transaction 2. |
| 8434 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8435 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8436 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8437 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8438 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8439 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8440 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8441 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8442 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8443 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8444 | "hello world", "welcome" |
| 8445 | }; |
| 8446 | |
| 8447 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8448 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8450 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8451 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8452 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8454 | |
| 8455 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8456 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8459 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8460 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8461 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8462 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8463 | |
| 8464 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8465 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8467 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8468 | } |
| 8469 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8470 | |
| 8471 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8472 | // 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] | 8473 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8474 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8475 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8476 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8477 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8478 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8479 | request.traffic_annotation = |
| 8480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8482 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8484 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8485 | // The password contains an escaped character -- for this test to pass it |
| 8486 | // will need to be unescaped by HttpNetworkTransaction. |
| 8487 | EXPECT_EQ("b%40r", request.url.password()); |
| 8488 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8489 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8490 | MockWrite( |
| 8491 | "GET / HTTP/1.1\r\n" |
| 8492 | "Host: www.example.org\r\n" |
| 8493 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8494 | }; |
| 8495 | |
| 8496 | MockRead data_reads1[] = { |
| 8497 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8498 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8499 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8500 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8501 | }; |
| 8502 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8503 | // After the challenge above, the transaction will be restarted using the |
| 8504 | // identity from the url (foo, b@r) to answer the challenge. |
| 8505 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | MockWrite( |
| 8507 | "GET / HTTP/1.1\r\n" |
| 8508 | "Host: www.example.org\r\n" |
| 8509 | "Connection: keep-alive\r\n" |
| 8510 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8511 | }; |
| 8512 | |
| 8513 | MockRead data_reads2[] = { |
| 8514 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8515 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8516 | MockRead(SYNCHRONOUS, OK), |
| 8517 | }; |
| 8518 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8519 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8520 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8521 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8522 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8524 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8525 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8527 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8528 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8529 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8530 | |
| 8531 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8532 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8534 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8535 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8536 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8538 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8539 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8540 | |
| 8541 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8542 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8543 | |
| 8544 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8545 | |
| 8546 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8547 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8548 | } |
| 8549 | |
| 8550 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8551 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8552 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8553 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8554 | HttpRequestInfo request; |
| 8555 | request.method = "GET"; |
| 8556 | // Note: the URL has a username:password in it. The password "baz" is |
| 8557 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8558 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8559 | |
| 8560 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8561 | request.traffic_annotation = |
| 8562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8565 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8566 | |
| 8567 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8568 | MockWrite( |
| 8569 | "GET / HTTP/1.1\r\n" |
| 8570 | "Host: www.example.org\r\n" |
| 8571 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8572 | }; |
| 8573 | |
| 8574 | MockRead data_reads1[] = { |
| 8575 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8576 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8577 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8578 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8579 | }; |
| 8580 | |
| 8581 | // After the challenge above, the transaction will be restarted using the |
| 8582 | // identity from the url (foo, baz) to answer the challenge. |
| 8583 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8584 | MockWrite( |
| 8585 | "GET / HTTP/1.1\r\n" |
| 8586 | "Host: www.example.org\r\n" |
| 8587 | "Connection: keep-alive\r\n" |
| 8588 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8589 | }; |
| 8590 | |
| 8591 | MockRead data_reads2[] = { |
| 8592 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8593 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8594 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8595 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8596 | }; |
| 8597 | |
| 8598 | // After the challenge above, the transaction will be restarted using the |
| 8599 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8600 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8601 | MockWrite( |
| 8602 | "GET / HTTP/1.1\r\n" |
| 8603 | "Host: www.example.org\r\n" |
| 8604 | "Connection: keep-alive\r\n" |
| 8605 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8606 | }; |
| 8607 | |
| 8608 | MockRead data_reads3[] = { |
| 8609 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8610 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8611 | MockRead(SYNCHRONOUS, OK), |
| 8612 | }; |
| 8613 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8614 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8615 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8616 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8617 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8618 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8619 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8620 | |
| 8621 | TestCompletionCallback callback1; |
| 8622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8623 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8625 | |
| 8626 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8628 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8629 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8630 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8631 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8633 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8634 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8635 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8637 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8638 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8639 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8640 | |
| 8641 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8642 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
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 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8645 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8646 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8648 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8649 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | |
| 8651 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8652 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8653 | |
| 8654 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8655 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8656 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8657 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8658 | } |
| 8659 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8660 | |
| 8661 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8662 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8663 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8664 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8665 | HttpRequestInfo request; |
| 8666 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8667 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8668 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8669 | request.traffic_annotation = |
| 8670 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8671 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8674 | |
| 8675 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8676 | MockWrite( |
| 8677 | "GET / HTTP/1.1\r\n" |
| 8678 | "Host: www.example.org\r\n" |
| 8679 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8680 | }; |
| 8681 | |
| 8682 | MockRead data_reads1[] = { |
| 8683 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8684 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8685 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8686 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8687 | }; |
| 8688 | |
| 8689 | // After the challenge above, the transaction will be restarted using the |
| 8690 | // identity supplied by the user, not the one in the URL, to answer the |
| 8691 | // challenge. |
| 8692 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8693 | MockWrite( |
| 8694 | "GET / HTTP/1.1\r\n" |
| 8695 | "Host: www.example.org\r\n" |
| 8696 | "Connection: keep-alive\r\n" |
| 8697 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8698 | }; |
| 8699 | |
| 8700 | MockRead data_reads3[] = { |
| 8701 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8702 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8703 | MockRead(SYNCHRONOUS, OK), |
| 8704 | }; |
| 8705 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8706 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8707 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8708 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8709 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8710 | |
| 8711 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8712 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8713 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8714 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8715 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8716 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8719 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8720 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8721 | |
| 8722 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8723 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8725 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8726 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8727 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8729 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8730 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8731 | |
| 8732 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8733 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8734 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8735 | |
| 8736 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8737 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8738 | } |
| 8739 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8740 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8741 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8743 | |
| 8744 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8745 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8746 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8747 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8748 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8749 | request.traffic_annotation = |
| 8750 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8752 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8753 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8754 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8755 | MockWrite( |
| 8756 | "GET /x/y/z HTTP/1.1\r\n" |
| 8757 | "Host: www.example.org\r\n" |
| 8758 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8759 | }; |
| 8760 | |
| 8761 | MockRead data_reads1[] = { |
| 8762 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8763 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8764 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8765 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8766 | }; |
| 8767 | |
| 8768 | // Resend with authorization (username=foo, password=bar) |
| 8769 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8770 | MockWrite( |
| 8771 | "GET /x/y/z HTTP/1.1\r\n" |
| 8772 | "Host: www.example.org\r\n" |
| 8773 | "Connection: keep-alive\r\n" |
| 8774 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8775 | }; |
| 8776 | |
| 8777 | // Sever accepts the authorization. |
| 8778 | MockRead data_reads2[] = { |
| 8779 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8780 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8781 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8782 | }; |
| 8783 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8784 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8785 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8786 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8787 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8788 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8789 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8790 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8791 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8793 | |
| 8794 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8795 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8797 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8798 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8799 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8800 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8801 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8803 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8804 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8806 | |
| 8807 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8808 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8810 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8811 | ASSERT_TRUE(response); |
| 8812 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8813 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8814 | } |
| 8815 | |
| 8816 | // ------------------------------------------------------------------------ |
| 8817 | |
| 8818 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8819 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8820 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8821 | request.method = "GET"; |
| 8822 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8823 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8824 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8825 | request.traffic_annotation = |
| 8826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8829 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8830 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8831 | MockWrite( |
| 8832 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8833 | "Host: www.example.org\r\n" |
| 8834 | "Connection: keep-alive\r\n" |
| 8835 | // Send preemptive authorization for MyRealm1 |
| 8836 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8837 | }; |
| 8838 | |
| 8839 | // The server didn't like the preemptive authorization, and |
| 8840 | // challenges us for a different realm (MyRealm2). |
| 8841 | MockRead data_reads1[] = { |
| 8842 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8843 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8844 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8845 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8846 | }; |
| 8847 | |
| 8848 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8849 | MockWrite data_writes2[] = { |
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 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8855 | }; |
| 8856 | |
| 8857 | // Sever accepts the authorization. |
| 8858 | MockRead data_reads2[] = { |
| 8859 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8860 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8861 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8862 | }; |
| 8863 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8864 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8865 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8866 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8867 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8869 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8870 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8871 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8873 | |
| 8874 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8875 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8877 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8878 | ASSERT_TRUE(response); |
| 8879 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8880 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8881 | EXPECT_EQ("http://www.example.org", |
| 8882 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8883 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8884 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8886 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8888 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8889 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8891 | |
| 8892 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8894 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8895 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8896 | ASSERT_TRUE(response); |
| 8897 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8898 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8899 | } |
| 8900 | |
| 8901 | // ------------------------------------------------------------------------ |
| 8902 | |
| 8903 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8904 | // succeed with preemptive authorization. |
| 8905 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8906 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8907 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8908 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8909 | request.traffic_annotation = |
| 8910 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8912 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8913 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8914 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8915 | MockWrite( |
| 8916 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8917 | "Host: www.example.org\r\n" |
| 8918 | "Connection: keep-alive\r\n" |
| 8919 | // The authorization for MyRealm1 gets sent preemptively |
| 8920 | // (since the url is in the same protection space) |
| 8921 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8922 | }; |
| 8923 | |
| 8924 | // Sever accepts the preemptive authorization |
| 8925 | MockRead data_reads1[] = { |
| 8926 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8927 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8928 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8929 | }; |
| 8930 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8931 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8934 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8935 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8936 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8938 | |
| 8939 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8940 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8942 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8943 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8944 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8945 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8946 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8947 | } |
| 8948 | |
| 8949 | // ------------------------------------------------------------------------ |
| 8950 | |
| 8951 | // Transaction 4: request another URL in MyRealm (however the |
| 8952 | // url is not known to belong to the protection space, so no pre-auth). |
| 8953 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8954 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8955 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8956 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8957 | request.traffic_annotation = |
| 8958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8960 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8961 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8962 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8963 | MockWrite( |
| 8964 | "GET /x/1 HTTP/1.1\r\n" |
| 8965 | "Host: www.example.org\r\n" |
| 8966 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8967 | }; |
| 8968 | |
| 8969 | MockRead data_reads1[] = { |
| 8970 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8971 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8972 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8973 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8974 | }; |
| 8975 | |
| 8976 | // Resend with authorization from MyRealm's cache. |
| 8977 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8978 | MockWrite( |
| 8979 | "GET /x/1 HTTP/1.1\r\n" |
| 8980 | "Host: www.example.org\r\n" |
| 8981 | "Connection: keep-alive\r\n" |
| 8982 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8983 | }; |
| 8984 | |
| 8985 | // Sever accepts the authorization. |
| 8986 | MockRead data_reads2[] = { |
| 8987 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8988 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8989 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8990 | }; |
| 8991 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8992 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8993 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8994 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8995 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8997 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8998 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8999 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9001 | |
| 9002 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9003 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9005 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9006 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9007 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9009 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9010 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9011 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9013 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9014 | ASSERT_TRUE(response); |
| 9015 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9016 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9017 | } |
| 9018 | |
| 9019 | // ------------------------------------------------------------------------ |
| 9020 | |
| 9021 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9022 | // cached identity. Should invalidate and re-prompt. |
| 9023 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9024 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9025 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9026 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9027 | request.traffic_annotation = |
| 9028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9031 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9032 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9033 | MockWrite( |
| 9034 | "GET /p/q/t HTTP/1.1\r\n" |
| 9035 | "Host: www.example.org\r\n" |
| 9036 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9037 | }; |
| 9038 | |
| 9039 | MockRead data_reads1[] = { |
| 9040 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9041 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9042 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9043 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9044 | }; |
| 9045 | |
| 9046 | // Resend with authorization from cache for MyRealm. |
| 9047 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9048 | MockWrite( |
| 9049 | "GET /p/q/t HTTP/1.1\r\n" |
| 9050 | "Host: www.example.org\r\n" |
| 9051 | "Connection: keep-alive\r\n" |
| 9052 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9053 | }; |
| 9054 | |
| 9055 | // Sever rejects the authorization. |
| 9056 | MockRead data_reads2[] = { |
| 9057 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9058 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9059 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9060 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9061 | }; |
| 9062 | |
| 9063 | // At this point we should prompt for new credentials for MyRealm. |
| 9064 | // Restart with username=foo3, password=foo4. |
| 9065 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9066 | MockWrite( |
| 9067 | "GET /p/q/t HTTP/1.1\r\n" |
| 9068 | "Host: www.example.org\r\n" |
| 9069 | "Connection: keep-alive\r\n" |
| 9070 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9071 | }; |
| 9072 | |
| 9073 | // Sever accepts the authorization. |
| 9074 | MockRead data_reads3[] = { |
| 9075 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9076 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9077 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9078 | }; |
| 9079 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9080 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9081 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9082 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9083 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9084 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9085 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9087 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9088 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9089 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | |
| 9092 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9095 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9096 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9097 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9099 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9100 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9101 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9103 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9104 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9105 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9107 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9108 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9109 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9110 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9112 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9113 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9116 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9117 | ASSERT_TRUE(response); |
| 9118 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9119 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9120 | } |
| 9121 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9122 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9123 | // Tests that nonce count increments when multiple auth attempts |
| 9124 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9125 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9126 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9127 | new HttpAuthHandlerDigest::Factory(); |
| 9128 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9129 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9130 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9131 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9133 | |
| 9134 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9135 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9136 | HttpRequestInfo request; |
| 9137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9138 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9139 | request.traffic_annotation = |
| 9140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9143 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9144 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9145 | MockWrite( |
| 9146 | "GET /x/y/z HTTP/1.1\r\n" |
| 9147 | "Host: www.example.org\r\n" |
| 9148 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9149 | }; |
| 9150 | |
| 9151 | MockRead data_reads1[] = { |
| 9152 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9153 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9154 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9155 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9156 | }; |
| 9157 | |
| 9158 | // Resend with authorization (username=foo, password=bar) |
| 9159 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9160 | MockWrite( |
| 9161 | "GET /x/y/z HTTP/1.1\r\n" |
| 9162 | "Host: www.example.org\r\n" |
| 9163 | "Connection: keep-alive\r\n" |
| 9164 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9165 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9166 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9167 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9168 | }; |
| 9169 | |
| 9170 | // Sever accepts the authorization. |
| 9171 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9172 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9173 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9174 | }; |
| 9175 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9176 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9177 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9178 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9179 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9181 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9182 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9183 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9185 | |
| 9186 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9187 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9188 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9189 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9190 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9191 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9193 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9195 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9196 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9198 | |
| 9199 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9200 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9202 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9203 | ASSERT_TRUE(response); |
| 9204 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9205 | } |
| 9206 | |
| 9207 | // ------------------------------------------------------------------------ |
| 9208 | |
| 9209 | // Transaction 2: Request another resource in digestive's protection space. |
| 9210 | // This will preemptively add an Authorization header which should have an |
| 9211 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9212 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9213 | HttpRequestInfo request; |
| 9214 | request.method = "GET"; |
| 9215 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9216 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9217 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9218 | request.traffic_annotation = |
| 9219 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9220 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9221 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9222 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9223 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9224 | MockWrite( |
| 9225 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9226 | "Host: www.example.org\r\n" |
| 9227 | "Connection: keep-alive\r\n" |
| 9228 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9229 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9230 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9231 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9232 | }; |
| 9233 | |
| 9234 | // Sever accepts the authorization. |
| 9235 | MockRead data_reads1[] = { |
| 9236 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9237 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9238 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9239 | }; |
| 9240 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9241 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9244 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9245 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9246 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9248 | |
| 9249 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9253 | ASSERT_TRUE(response); |
| 9254 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9255 | } |
| 9256 | } |
| 9257 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9258 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9259 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9260 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9263 | |
| 9264 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9265 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9266 | trans.read_buf_len_ = 15; |
| 9267 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9268 | |
| 9269 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9270 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9271 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9272 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9273 | response->response_time = base::Time::Now(); |
| 9274 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9275 | |
| 9276 | { // Setup state for response_.vary_data |
| 9277 | HttpRequestInfo request; |
| 9278 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9279 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9280 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9281 | request.extra_headers.SetHeader("Foo", "1"); |
| 9282 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9283 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9284 | } |
| 9285 | |
| 9286 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9287 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9288 | |
| 9289 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9290 | EXPECT_FALSE(trans.read_buf_); |
| 9291 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9292 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9293 | EXPECT_FALSE(response->auth_challenge); |
| 9294 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9295 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9296 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9297 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9298 | } |
| 9299 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9300 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9301 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9302 | HttpRequestInfo request; |
| 9303 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9304 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9305 | request.traffic_annotation = |
| 9306 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9307 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9309 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9310 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9311 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9312 | MockWrite( |
| 9313 | "GET / HTTP/1.1\r\n" |
| 9314 | "Host: www.example.org\r\n" |
| 9315 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9316 | }; |
| 9317 | |
| 9318 | MockRead data_reads[] = { |
| 9319 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9320 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9321 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9322 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9323 | }; |
| 9324 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9325 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9326 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9327 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9328 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9329 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9330 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9331 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9335 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9336 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9337 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9339 | |
| 9340 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9341 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9342 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9343 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9344 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9345 | |
| 9346 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9347 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9348 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9349 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9350 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9351 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9352 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9353 | } |
| 9354 | |
| 9355 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9356 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9357 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9358 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9359 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9360 | |
| 9361 | HttpRequestInfo request; |
| 9362 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9363 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9364 | request.traffic_annotation = |
| 9365 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9366 | |
| 9367 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9368 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9369 | "Host: www.example.org:443\r\n" |
| 9370 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9371 | }; |
| 9372 | |
| 9373 | MockRead proxy_reads[] = { |
| 9374 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9375 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9376 | }; |
| 9377 | |
| 9378 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9379 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9380 | "Host: www.example.org:443\r\n" |
| 9381 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9382 | MockWrite("GET / HTTP/1.1\r\n" |
| 9383 | "Host: www.example.org\r\n" |
| 9384 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9385 | }; |
| 9386 | |
| 9387 | MockRead data_reads[] = { |
| 9388 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9389 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9390 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9391 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9392 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9393 | }; |
| 9394 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9395 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9396 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9397 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9398 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9399 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9400 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9405 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9406 | |
| 9407 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9408 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9409 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9412 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9413 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9415 | |
| 9416 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9417 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9419 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9421 | |
| 9422 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9424 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9425 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9426 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9427 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9428 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9429 | } |
| 9430 | } |
| 9431 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9432 | |
| 9433 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9434 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9435 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9436 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9437 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9438 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9439 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9440 | |
| 9441 | HttpRequestInfo request; |
| 9442 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9443 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9444 | request.traffic_annotation = |
| 9445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9446 | |
| 9447 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9448 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9449 | "Host: www.example.org:443\r\n" |
| 9450 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9451 | MockWrite("GET / HTTP/1.1\r\n" |
| 9452 | "Host: www.example.org\r\n" |
| 9453 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9454 | }; |
| 9455 | |
| 9456 | MockRead data_reads[] = { |
| 9457 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9458 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9459 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9460 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9462 | }; |
| 9463 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9464 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9465 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9466 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9467 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9468 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9469 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9472 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9476 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9477 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9479 | |
| 9480 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9481 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9482 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9483 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9484 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9485 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9486 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9487 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9488 | EXPECT_EQ(200, response->headers->response_code()); |
| 9489 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9490 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9491 | |
| 9492 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9493 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9494 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9495 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9496 | } |
| 9497 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9498 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9499 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9500 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9501 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9502 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9503 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9504 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9505 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9506 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9507 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9508 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9509 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9510 | HttpRequestInfo request; |
| 9511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9512 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9513 | request.traffic_annotation = |
| 9514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9515 | |
| 9516 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9517 | MockWrite(ASYNC, 0, |
| 9518 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9519 | "Host: www.example.org:443\r\n" |
| 9520 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9521 | }; |
| 9522 | |
| 9523 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9524 | // Pause on first read. |
| 9525 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9526 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9527 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9528 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9529 | }; |
| 9530 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9531 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9532 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9533 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9537 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9538 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9539 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9540 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9541 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9542 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9544 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9545 | |
| 9546 | // Host resolution takes |kTimeIncrement|. |
| 9547 | FastForwardBy(kTimeIncrement); |
| 9548 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9549 | // request to instantly complete, and the async connect will start as well. |
| 9550 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9551 | |
| 9552 | // Connecting takes |kTimeIncrement|. |
| 9553 | FastForwardBy(kTimeIncrement); |
| 9554 | data.RunUntilPaused(); |
| 9555 | |
| 9556 | // The server takes |kTimeIncrement| to respond. |
| 9557 | FastForwardBy(kTimeIncrement); |
| 9558 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9559 | |
| 9560 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9561 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9562 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9563 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9564 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9565 | |
| 9566 | EXPECT_EQ(302, response->headers->response_code()); |
| 9567 | std::string url; |
| 9568 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9569 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9570 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9571 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9572 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9573 | |
| 9574 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9575 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9576 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9577 | // In the case of redirects from proxies, just as with all responses from |
| 9578 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9579 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9580 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9581 | // connect_start / connect_end. See |
| 9582 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 9583 | |
| 9584 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9585 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9586 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9587 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9588 | |
| 9589 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_start); |
| 9590 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_end); |
| 9591 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9592 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9593 | load_timing_info.connect_timing.connect_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9594 | |
| 9595 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9596 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9597 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9598 | } |
| 9599 | |
| 9600 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9601 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9602 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9603 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9604 | TestNetLog net_log; |
| 9605 | session_deps_.net_log = &net_log; |
| 9606 | |
| 9607 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9608 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9609 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9610 | |
| 9611 | HttpRequestInfo request; |
| 9612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9613 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9614 | request.traffic_annotation = |
| 9615 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9616 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9617 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9618 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9619 | spdy::SpdySerializedFrame goaway( |
| 9620 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9621 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9622 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9623 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9624 | }; |
| 9625 | |
| 9626 | static const char* const kExtraHeaders[] = { |
| 9627 | "location", |
| 9628 | "http://login.example.com/", |
| 9629 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9630 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9631 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9632 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9633 | // Pause on first read. |
| 9634 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9635 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9636 | }; |
| 9637 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9638 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9639 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9640 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9641 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9643 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9644 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9645 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9646 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9648 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9650 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9652 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9653 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9654 | // Host resolution takes |kTimeIncrement|. |
| 9655 | FastForwardBy(kTimeIncrement); |
| 9656 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9657 | // request to instantly complete, and the async connect will start as well. |
| 9658 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9659 | |
| 9660 | // Connecting takes |kTimeIncrement|. |
| 9661 | FastForwardBy(kTimeIncrement); |
| 9662 | data.RunUntilPaused(); |
| 9663 | |
| 9664 | FastForwardBy(kTimeIncrement); |
| 9665 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9666 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9667 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9669 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9670 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9671 | |
| 9672 | EXPECT_EQ(302, response->headers->response_code()); |
| 9673 | std::string url; |
| 9674 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9675 | EXPECT_EQ("http://login.example.com/", url); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9676 | |
| 9677 | LoadTimingInfo load_timing_info; |
| 9678 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 9679 | |
| 9680 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 9681 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 9682 | |
| 9683 | // No proxy resolution times, since there's no PAC script. |
| 9684 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 9685 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 9686 | |
| 9687 | // In the case of redirects from proxies, just as with all responses from |
| 9688 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9689 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9690 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9691 | // connect_start / connect_end. See |
| 9692 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 9693 | |
| 9694 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9695 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9696 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9697 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9698 | |
| 9699 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9700 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9701 | load_timing_info.connect_timing.connect_end); |
| 9702 | |
| 9703 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9704 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9705 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9706 | } |
| 9707 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9708 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9709 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9710 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9711 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9712 | |
| 9713 | HttpRequestInfo request; |
| 9714 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9715 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9716 | request.traffic_annotation = |
| 9717 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9718 | |
| 9719 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9720 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9721 | "Host: www.example.org:443\r\n" |
| 9722 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9723 | }; |
| 9724 | |
| 9725 | MockRead data_reads[] = { |
| 9726 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9727 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9728 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9729 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9730 | }; |
| 9731 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9732 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9733 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9734 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9735 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9736 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9738 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9739 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9740 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9741 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9742 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9743 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9745 | |
| 9746 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9747 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9748 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9749 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9750 | } |
| 9751 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9752 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9753 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9754 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9755 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9756 | |
| 9757 | HttpRequestInfo request; |
| 9758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9759 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9760 | request.traffic_annotation = |
| 9761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9762 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9763 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9764 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9765 | spdy::SpdySerializedFrame rst( |
| 9766 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9767 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9768 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9769 | }; |
| 9770 | |
| 9771 | static const char* const kExtraHeaders[] = { |
| 9772 | "location", |
| 9773 | "http://login.example.com/", |
| 9774 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9775 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9776 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9777 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9778 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9779 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9780 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9781 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9782 | }; |
| 9783 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9784 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9785 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9786 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9787 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9791 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9795 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9796 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9798 | |
| 9799 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9800 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9801 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9802 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9803 | } |
| 9804 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9805 | // Test the request-challenge-retry sequence for basic auth, through |
| 9806 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9807 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9808 | HttpRequestInfo request; |
| 9809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9810 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9811 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9812 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9813 | request.traffic_annotation = |
| 9814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9815 | |
| 9816 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9817 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9818 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9819 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9820 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9821 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9823 | |
| 9824 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9825 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9826 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9827 | spdy::SpdySerializedFrame rst( |
| 9828 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9829 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9831 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9832 | // be issuing -- the final header line contains the credentials. |
| 9833 | const char* const kAuthCredentials[] = { |
| 9834 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9835 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9836 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9837 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9838 | HostPortPair("www.example.org", 443))); |
| 9839 | // fetch https://www.example.org/ via HTTP |
| 9840 | const char get[] = |
| 9841 | "GET / HTTP/1.1\r\n" |
| 9842 | "Host: www.example.org\r\n" |
| 9843 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9844 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9845 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9846 | |
| 9847 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9848 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9849 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9850 | }; |
| 9851 | |
| 9852 | // The proxy responds to the connect with a 407, using a persistent |
| 9853 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9854 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9855 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9856 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9857 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9858 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9859 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9860 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9861 | spdy::SpdySerializedFrame conn_resp( |
| 9862 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9863 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9864 | "Content-Length: 5\r\n\r\n"; |
| 9865 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9866 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9867 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9868 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9869 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9870 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9871 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9872 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9873 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9874 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9875 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9876 | }; |
| 9877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9878 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9879 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9880 | // Negotiate SPDY to the proxy |
| 9881 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9882 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9884 | // Vanilla SSL to the server |
| 9885 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9887 | |
| 9888 | TestCompletionCallback callback1; |
| 9889 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9890 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9891 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9892 | |
| 9893 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9895 | |
| 9896 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9897 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9898 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9899 | log.GetEntries(&entries); |
| 9900 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9901 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9902 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9903 | ExpectLogContainsSomewhere( |
| 9904 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9905 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9906 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9907 | |
| 9908 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9909 | ASSERT_TRUE(response); |
| 9910 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9911 | EXPECT_EQ(407, response->headers->response_code()); |
| 9912 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9913 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9914 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9915 | |
| 9916 | TestCompletionCallback callback2; |
| 9917 | |
| 9918 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9919 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9921 | |
| 9922 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9923 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9924 | |
| 9925 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9926 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9927 | |
| 9928 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9929 | EXPECT_EQ(200, response->headers->response_code()); |
| 9930 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9931 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9932 | |
| 9933 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9934 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9935 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9936 | LoadTimingInfo load_timing_info; |
| 9937 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9938 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9939 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9940 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9941 | trans.reset(); |
| 9942 | session->CloseAllConnections(); |
| 9943 | } |
| 9944 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9945 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9946 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9947 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9948 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9949 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9950 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9951 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9952 | HttpRequestInfo request; |
| 9953 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9954 | request.traffic_annotation = |
| 9955 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9956 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9957 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9958 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9959 | push_request.method = "GET"; |
| 9960 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9961 | push_request.traffic_annotation = |
| 9962 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9963 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9964 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9965 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9966 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9967 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9968 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9969 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9970 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9971 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9972 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9973 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9974 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9975 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9976 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9977 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9978 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9979 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9980 | |
| 9981 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9982 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9983 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9984 | }; |
| 9985 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9986 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9987 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9988 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9989 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9990 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9991 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9992 | spdy::SpdySerializedFrame stream1_body( |
| 9993 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9994 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9995 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9996 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9997 | |
| 9998 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9999 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10000 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10001 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10002 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10003 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10004 | }; |
| 10005 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10006 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10007 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10008 | // Negotiate SPDY to the proxy |
| 10009 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10010 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10011 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10012 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10013 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10014 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10015 | TestCompletionCallback callback; |
| 10016 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10018 | |
| 10019 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10020 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10021 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10022 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10023 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10024 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10025 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10027 | |
| 10028 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10029 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10030 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10031 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10032 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10033 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10034 | |
| 10035 | EXPECT_EQ(200, response->headers->response_code()); |
| 10036 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10037 | |
| 10038 | std::string response_data; |
| 10039 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10040 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10041 | EXPECT_EQ("hello!", response_data); |
| 10042 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10043 | LoadTimingInfo load_timing_info; |
| 10044 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10045 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10046 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10047 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10048 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10049 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10050 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10051 | |
| 10052 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10053 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10054 | EXPECT_EQ("pushed", response_data); |
| 10055 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10056 | LoadTimingInfo push_load_timing_info; |
| 10057 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10058 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10059 | // The transactions should share a socket ID, despite being for different |
| 10060 | // origins. |
| 10061 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10062 | push_load_timing_info.socket_log_id); |
| 10063 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10064 | trans.reset(); |
| 10065 | push_trans.reset(); |
| 10066 | session->CloseAllConnections(); |
| 10067 | } |
| 10068 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10069 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10070 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10071 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10072 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10073 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10074 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10075 | HttpRequestInfo request; |
| 10076 | |
| 10077 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10078 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10079 | request.traffic_annotation = |
| 10080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10081 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10082 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10083 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10084 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10085 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10086 | |
| 10087 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10088 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10089 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10090 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10092 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10093 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10094 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10095 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10096 | spdy::SpdySerializedFrame push_rst( |
| 10097 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10098 | |
| 10099 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10100 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10101 | }; |
| 10102 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10103 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10104 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10105 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10106 | spdy::SpdySerializedFrame stream1_body( |
| 10107 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10108 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10109 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10110 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10111 | |
| 10112 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10113 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10114 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10115 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10116 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10117 | }; |
| 10118 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10119 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10120 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10121 | // Negotiate SPDY to the proxy |
| 10122 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10123 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10125 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10126 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10127 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10128 | TestCompletionCallback callback; |
| 10129 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10131 | |
| 10132 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10134 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10135 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10136 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10137 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10138 | |
| 10139 | EXPECT_EQ(200, response->headers->response_code()); |
| 10140 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10141 | |
| 10142 | std::string response_data; |
| 10143 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10145 | EXPECT_EQ("hello!", response_data); |
| 10146 | |
| 10147 | trans.reset(); |
| 10148 | session->CloseAllConnections(); |
| 10149 | } |
| 10150 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10151 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10152 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10153 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10154 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10155 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10156 | proxy_delegate->set_trusted_spdy_proxy( |
| 10157 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10158 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10159 | HttpRequestInfo request; |
| 10160 | |
| 10161 | request.method = "GET"; |
| 10162 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10163 | request.traffic_annotation = |
| 10164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10165 | |
| 10166 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10167 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10168 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10169 | BoundTestNetLog log; |
| 10170 | session_deps_.net_log = log.bound().net_log(); |
| 10171 | |
| 10172 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10173 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10174 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10177 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10178 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10179 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10180 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10181 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10182 | |
| 10183 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10184 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10185 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10186 | }; |
| 10187 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10188 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10189 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10190 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10191 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10192 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10193 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10194 | spdy::SpdySerializedFrame stream1_body( |
| 10195 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10196 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10197 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10198 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10199 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10200 | spdy::SpdySerializedFrame stream2_body( |
| 10201 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10202 | |
| 10203 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10204 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10205 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10206 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10207 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10208 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10209 | }; |
| 10210 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10211 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10212 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10213 | // Negotiate SPDY to the proxy |
| 10214 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10215 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10217 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10218 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10219 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10220 | TestCompletionCallback callback; |
| 10221 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10222 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10223 | |
| 10224 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10225 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10226 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10227 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10228 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10229 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10230 | |
| 10231 | EXPECT_EQ(200, response->headers->response_code()); |
| 10232 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10233 | |
| 10234 | std::string response_data; |
| 10235 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10236 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10237 | EXPECT_EQ("hello!", response_data); |
| 10238 | |
| 10239 | trans.reset(); |
| 10240 | session->CloseAllConnections(); |
| 10241 | } |
| 10242 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10243 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10244 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10245 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10246 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10247 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10248 | |
| 10249 | HttpRequestInfo request; |
| 10250 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10251 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10252 | request.traffic_annotation = |
| 10253 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10254 | |
| 10255 | // Attempt to fetch the URL from a server with a bad cert |
| 10256 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10257 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10258 | "Host: www.example.org:443\r\n" |
| 10259 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10260 | }; |
| 10261 | |
| 10262 | MockRead bad_cert_reads[] = { |
| 10263 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10264 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10265 | }; |
| 10266 | |
| 10267 | // Attempt to fetch the URL with a good cert |
| 10268 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10269 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10270 | "Host: www.example.org:443\r\n" |
| 10271 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10272 | MockWrite("GET / HTTP/1.1\r\n" |
| 10273 | "Host: www.example.org\r\n" |
| 10274 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10275 | }; |
| 10276 | |
| 10277 | MockRead good_cert_reads[] = { |
| 10278 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10279 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10281 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10282 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10283 | }; |
| 10284 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10285 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10286 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10287 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10288 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10289 | |
| 10290 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10291 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10292 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10294 | |
| 10295 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10297 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10300 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10301 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10302 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10303 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10304 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10305 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10306 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10307 | |
| 10308 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10309 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10311 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10313 | |
| 10314 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10315 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10316 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10317 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10318 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10319 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10320 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10321 | } |
| 10322 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10323 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10324 | HttpRequestInfo request; |
| 10325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10326 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10327 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10328 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10329 | request.traffic_annotation = |
| 10330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10331 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10333 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10334 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10335 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10336 | MockWrite( |
| 10337 | "GET / HTTP/1.1\r\n" |
| 10338 | "Host: www.example.org\r\n" |
| 10339 | "Connection: keep-alive\r\n" |
| 10340 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10341 | }; |
| 10342 | |
| 10343 | // Lastly, the server responds with the actual content. |
| 10344 | MockRead data_reads[] = { |
| 10345 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10346 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10347 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10349 | }; |
| 10350 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10351 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10352 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10353 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10354 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10355 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10356 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10358 | |
| 10359 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10360 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10361 | } |
| 10362 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10363 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10364 | HttpRequestInfo request; |
| 10365 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10366 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10367 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10368 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10369 | request.traffic_annotation = |
| 10370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10371 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10372 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10373 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10375 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10376 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10377 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10378 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10379 | "Host: www.example.org:443\r\n" |
| 10380 | "Proxy-Connection: keep-alive\r\n" |
| 10381 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10382 | }; |
| 10383 | MockRead data_reads[] = { |
| 10384 | // Return an error, so the transaction stops here (this test isn't |
| 10385 | // interested in the rest). |
| 10386 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10387 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10388 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10389 | }; |
| 10390 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10391 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10392 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10394 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10396 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10398 | |
| 10399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10401 | } |
| 10402 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10403 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10404 | HttpRequestInfo request; |
| 10405 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10406 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10407 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10408 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10409 | request.traffic_annotation = |
| 10410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10414 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10415 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10416 | MockWrite( |
| 10417 | "GET / HTTP/1.1\r\n" |
| 10418 | "Host: www.example.org\r\n" |
| 10419 | "Connection: keep-alive\r\n" |
| 10420 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10421 | }; |
| 10422 | |
| 10423 | // Lastly, the server responds with the actual content. |
| 10424 | MockRead data_reads[] = { |
| 10425 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10426 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10427 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10428 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10429 | }; |
| 10430 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10431 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10432 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10434 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10438 | |
| 10439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10441 | } |
| 10442 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10443 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10444 | HttpRequestInfo request; |
| 10445 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10446 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10447 | request.traffic_annotation = |
| 10448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10452 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10453 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10454 | MockWrite( |
| 10455 | "POST / HTTP/1.1\r\n" |
| 10456 | "Host: www.example.org\r\n" |
| 10457 | "Connection: keep-alive\r\n" |
| 10458 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10459 | }; |
| 10460 | |
| 10461 | // Lastly, the server responds with the actual content. |
| 10462 | MockRead data_reads[] = { |
| 10463 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10464 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10465 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10466 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10467 | }; |
| 10468 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10469 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10472 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10474 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10476 | |
| 10477 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10479 | } |
| 10480 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10481 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10482 | HttpRequestInfo request; |
| 10483 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10484 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10485 | request.traffic_annotation = |
| 10486 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10489 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10490 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10491 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10492 | MockWrite( |
| 10493 | "PUT / HTTP/1.1\r\n" |
| 10494 | "Host: www.example.org\r\n" |
| 10495 | "Connection: keep-alive\r\n" |
| 10496 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10497 | }; |
| 10498 | |
| 10499 | // Lastly, the server responds with the actual content. |
| 10500 | MockRead data_reads[] = { |
| 10501 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10502 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10503 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10504 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10505 | }; |
| 10506 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10507 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10508 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10510 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10512 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10514 | |
| 10515 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10517 | } |
| 10518 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10519 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10520 | HttpRequestInfo request; |
| 10521 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10522 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10523 | request.traffic_annotation = |
| 10524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10528 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10529 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10530 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10531 | "Host: www.example.org\r\n" |
| 10532 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10533 | }; |
| 10534 | |
| 10535 | // Lastly, the server responds with the actual content. |
| 10536 | MockRead data_reads[] = { |
| 10537 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10538 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10539 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10540 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10541 | }; |
| 10542 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10543 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10544 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10545 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10546 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10547 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10548 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10549 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10550 | |
| 10551 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10552 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10553 | } |
| 10554 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10555 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10556 | HttpRequestInfo request; |
| 10557 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10558 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10559 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10560 | request.traffic_annotation = |
| 10561 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10562 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10563 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10564 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10565 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10566 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10567 | MockWrite( |
| 10568 | "GET / HTTP/1.1\r\n" |
| 10569 | "Host: www.example.org\r\n" |
| 10570 | "Connection: keep-alive\r\n" |
| 10571 | "Pragma: no-cache\r\n" |
| 10572 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10573 | }; |
| 10574 | |
| 10575 | // Lastly, the server responds with the actual content. |
| 10576 | MockRead data_reads[] = { |
| 10577 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10578 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10579 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10580 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10581 | }; |
| 10582 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10583 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10584 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10586 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10587 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10588 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10590 | |
| 10591 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10592 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10593 | } |
| 10594 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10595 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10596 | HttpRequestInfo request; |
| 10597 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10598 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10599 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10600 | request.traffic_annotation = |
| 10601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10602 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10605 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10606 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10607 | MockWrite( |
| 10608 | "GET / HTTP/1.1\r\n" |
| 10609 | "Host: www.example.org\r\n" |
| 10610 | "Connection: keep-alive\r\n" |
| 10611 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10612 | }; |
| 10613 | |
| 10614 | // Lastly, the server responds with the actual content. |
| 10615 | MockRead data_reads[] = { |
| 10616 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10617 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10618 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10619 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10620 | }; |
| 10621 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10622 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10623 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10625 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10626 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10627 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10629 | |
| 10630 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10632 | } |
| 10633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10634 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10635 | HttpRequestInfo request; |
| 10636 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10637 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10638 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10639 | request.traffic_annotation = |
| 10640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10644 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10645 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10646 | MockWrite( |
| 10647 | "GET / HTTP/1.1\r\n" |
| 10648 | "Host: www.example.org\r\n" |
| 10649 | "Connection: keep-alive\r\n" |
| 10650 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10651 | }; |
| 10652 | |
| 10653 | // Lastly, the server responds with the actual content. |
| 10654 | MockRead data_reads[] = { |
| 10655 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10656 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10657 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10658 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10659 | }; |
| 10660 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10661 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10662 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10663 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10664 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10665 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10666 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10668 | |
| 10669 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10670 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10671 | } |
| 10672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10673 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10674 | HttpRequestInfo request; |
| 10675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10676 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10677 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10678 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10679 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10680 | request.traffic_annotation = |
| 10681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10682 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10685 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10686 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10687 | MockWrite( |
| 10688 | "GET / HTTP/1.1\r\n" |
| 10689 | "Host: www.example.org\r\n" |
| 10690 | "Connection: keep-alive\r\n" |
| 10691 | "referer: www.foo.com\r\n" |
| 10692 | "hEllo: Kitty\r\n" |
| 10693 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10694 | }; |
| 10695 | |
| 10696 | // Lastly, the server responds with the actual content. |
| 10697 | MockRead data_reads[] = { |
| 10698 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10699 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10700 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10701 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10702 | }; |
| 10703 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10704 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10705 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10707 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10709 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10711 | |
| 10712 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10713 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10714 | } |
| 10715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10716 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10717 | HttpRequestInfo request; |
| 10718 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10719 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10720 | request.traffic_annotation = |
| 10721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10722 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10723 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10724 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10725 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10726 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10727 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10731 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10732 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10733 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10734 | |
| 10735 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10736 | MockWrite(ASYNC, write_buffer, 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, read_buffer, base::size(read_buffer)), |
| 10743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10744 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10745 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10746 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10747 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10750 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10752 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10754 | |
| 10755 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10756 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10758 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10759 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10760 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10761 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[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_CONNECT_TIMES_ONLY); |
| 10766 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10767 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10768 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10769 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10770 | EXPECT_EQ("Payload", response_text); |
| 10771 | } |
| 10772 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10773 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10774 | HttpRequestInfo request; |
| 10775 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10776 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10777 | request.traffic_annotation = |
| 10778 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10779 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10780 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10781 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10782 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10783 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10784 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10788 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10789 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10790 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10791 | |
| 10792 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10793 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10794 | base::size(write_buffer)), |
| 10795 | MockWrite("GET / HTTP/1.1\r\n" |
| 10796 | "Host: www.example.org\r\n" |
| 10797 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10798 | |
| 10799 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10800 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10801 | base::size(read_buffer)), |
| 10802 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10803 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10804 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10805 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10806 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10807 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10808 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10809 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10812 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10813 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10814 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10816 | |
| 10817 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10818 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10819 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10820 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10821 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10822 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10823 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10825 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10826 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10827 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10828 | |
| 10829 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10830 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10831 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10832 | EXPECT_EQ("Payload", response_text); |
| 10833 | } |
| 10834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10835 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10836 | HttpRequestInfo request; |
| 10837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10838 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10839 | request.traffic_annotation = |
| 10840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10841 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10842 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10843 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10844 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10845 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10849 | |
| 10850 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10851 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10852 | |
| 10853 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10854 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10855 | MockWrite("GET / HTTP/1.1\r\n" |
| 10856 | "Host: www.example.org\r\n" |
| 10857 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10858 | |
| 10859 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10860 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10861 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10862 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10863 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10864 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10865 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10866 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10867 | |
| 10868 | TestCompletionCallback callback; |
| 10869 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10870 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10871 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10872 | |
| 10873 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10874 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10876 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10877 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10878 | |
| 10879 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10880 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10881 | TestLoadTimingNotReused(load_timing_info, |
| 10882 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10883 | |
| 10884 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10885 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10886 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10887 | EXPECT_EQ("Payload", response_text); |
| 10888 | } |
| 10889 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10890 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10891 | HttpRequestInfo request; |
| 10892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10893 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10894 | request.traffic_annotation = |
| 10895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10896 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10897 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10898 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10899 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10900 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10901 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10902 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10905 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10906 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10907 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10908 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10909 | 0x05, // Version |
| 10910 | 0x01, // Command (CONNECT) |
| 10911 | 0x00, // Reserved. |
| 10912 | 0x03, // Address type (DOMAINNAME). |
| 10913 | 0x0F, // Length of domain (15) |
| 10914 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10915 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10916 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10917 | const char kSOCKS5OkResponse[] = |
| 10918 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10919 | |
| 10920 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10921 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 10922 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 10923 | MockWrite("GET / HTTP/1.1\r\n" |
| 10924 | "Host: www.example.org\r\n" |
| 10925 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10926 | |
| 10927 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10928 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 10929 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 10930 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10931 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10932 | MockRead("Payload"), |
| 10933 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10934 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10935 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10938 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10942 | |
| 10943 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10944 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10946 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10947 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10948 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10949 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10950 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10951 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10952 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10953 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10954 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10955 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10956 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10957 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10958 | EXPECT_EQ("Payload", response_text); |
| 10959 | } |
| 10960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10961 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10962 | HttpRequestInfo request; |
| 10963 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10964 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10965 | request.traffic_annotation = |
| 10966 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10967 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10968 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10969 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10970 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10971 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10972 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10973 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10974 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10975 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10976 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10977 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10978 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10979 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10980 | 0x05, // Version |
| 10981 | 0x01, // Command (CONNECT) |
| 10982 | 0x00, // Reserved. |
| 10983 | 0x03, // Address type (DOMAINNAME). |
| 10984 | 0x0F, // Length of domain (15) |
| 10985 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10986 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10987 | }; |
| 10988 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10989 | const char kSOCKS5OkResponse[] = |
| 10990 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10991 | |
| 10992 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10993 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10994 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10995 | base::size(kSOCKS5OkRequest)), |
| 10996 | MockWrite("GET / HTTP/1.1\r\n" |
| 10997 | "Host: www.example.org\r\n" |
| 10998 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10999 | |
| 11000 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11001 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11002 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11003 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11004 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11005 | MockRead("Payload"), |
| 11006 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11007 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11008 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11009 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11010 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11011 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11012 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11014 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11015 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11016 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11018 | |
| 11019 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11020 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11022 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11023 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11024 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11025 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11026 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11027 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11028 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11029 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11030 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11031 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11032 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11033 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11034 | EXPECT_EQ("Payload", response_text); |
| 11035 | } |
| 11036 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11037 | namespace { |
| 11038 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11039 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11040 | |
| 11041 | struct GroupNameTest { |
| 11042 | std::string proxy_server; |
| 11043 | std::string url; |
| 11044 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11045 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11046 | }; |
| 11047 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11048 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11049 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11051 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11052 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11053 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11054 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11055 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11056 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11057 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11058 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11059 | |
| 11060 | return session; |
| 11061 | } |
| 11062 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11063 | int GroupNameTransactionHelper(const std::string& url, |
| 11064 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11065 | HttpRequestInfo request; |
| 11066 | request.method = "GET"; |
| 11067 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11068 | request.traffic_annotation = |
| 11069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11073 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11074 | |
| 11075 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11076 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11077 | } |
| 11078 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11079 | } // namespace |
| 11080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11081 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11082 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11083 | { |
| 11084 | "", // unused |
| 11085 | "http://www.example.org/direct", |
| 11086 | "www.example.org:80", |
| 11087 | false, |
| 11088 | }, |
| 11089 | { |
| 11090 | "", // unused |
| 11091 | "http://[2001:1418:13:1::25]/direct", |
| 11092 | "[2001:1418:13:1::25]:80", |
| 11093 | false, |
| 11094 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11095 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11096 | // SSL Tests |
| 11097 | { |
| 11098 | "", // unused |
| 11099 | "https://www.example.org/direct_ssl", |
| 11100 | "ssl/www.example.org:443", |
| 11101 | true, |
| 11102 | }, |
| 11103 | { |
| 11104 | "", // unused |
| 11105 | "https://[2001:1418:13:1::25]/direct", |
| 11106 | "ssl/[2001:1418:13:1::25]:443", |
| 11107 | true, |
| 11108 | }, |
| 11109 | { |
| 11110 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11111 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11112 | "ssl/host.with.alternate:443", |
| 11113 | true, |
| 11114 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11115 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 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] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11125 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11126 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11127 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11128 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11129 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11130 | |
| 11131 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11132 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11133 | EXPECT_EQ(tests[i].expected_group_name, |
| 11134 | transport_conn_pool->last_group_name_received()); |
| 11135 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11136 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11137 | } |
| 11138 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11139 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11140 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11141 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11142 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 11143 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11144 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11145 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11146 | // SSL Tests |
| 11147 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11148 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 11149 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11150 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11151 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11152 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11153 | "http_proxy", "https://host.with.alternate/direct", |
| 11154 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11155 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11156 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11157 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11158 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 11159 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11160 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11161 | }; |
| 11162 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11163 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11164 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11165 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11166 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11167 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11168 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11169 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11170 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11171 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11172 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11173 | HostPortPair("http_proxy", 80)); |
Matt Menke | 0754b5d0 | 2019-02-10 21:46:43 | [diff] [blame] | 11174 | CaptureGroupNameTransportSocketPool* http_proxy_pool = |
| 11175 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
Matt Menke | df126e0e | 2019-02-01 22:23:47 | [diff] [blame] | 11176 | CaptureGroupNameTransportSocketPool* ssl_conn_pool = |
| 11177 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11178 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11179 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11180 | proxy_server, base::WrapUnique(http_proxy_pool)); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11181 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11182 | proxy_server, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11183 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11184 | |
| 11185 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11186 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11187 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11188 | EXPECT_EQ(tests[i].expected_group_name, |
| 11189 | ssl_conn_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11190 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11191 | EXPECT_EQ(tests[i].expected_group_name, |
| 11192 | http_proxy_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11193 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11194 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11195 | } |
| 11196 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11197 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11198 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11199 | { |
| 11200 | "socks4://socks_proxy:1080", |
| 11201 | "http://www.example.org/socks4_direct", |
| 11202 | "socks4/www.example.org:80", |
| 11203 | false, |
| 11204 | }, |
| 11205 | { |
| 11206 | "socks5://socks_proxy:1080", |
| 11207 | "http://www.example.org/socks5_direct", |
| 11208 | "socks5/www.example.org:80", |
| 11209 | false, |
| 11210 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11211 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11212 | // SSL Tests |
| 11213 | { |
| 11214 | "socks4://socks_proxy:1080", |
| 11215 | "https://www.example.org/socks4_ssl", |
| 11216 | "socks4/ssl/www.example.org:443", |
| 11217 | true, |
| 11218 | }, |
| 11219 | { |
| 11220 | "socks5://socks_proxy:1080", |
| 11221 | "https://www.example.org/socks5_ssl", |
| 11222 | "socks5/ssl/www.example.org:443", |
| 11223 | true, |
| 11224 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11225 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11226 | { |
| 11227 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11228 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11229 | "socks4/ssl/host.with.alternate:443", |
| 11230 | true, |
| 11231 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11232 | }; |
| 11233 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11234 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11235 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11236 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11237 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11238 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11239 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11240 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11241 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11242 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11243 | ProxyServer proxy_server( |
| 11244 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11245 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 11246 | CaptureGroupNameTransportSocketPool* socks_conn_pool = |
| 11247 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11248 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 11249 | mock_pool_manager->SetSocketPoolForProxy(proxy_server, |
| 11250 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11251 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11254 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11255 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11256 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | 628d624f | 2019-02-09 00:40:24 | [diff] [blame] | 11257 | EXPECT_EQ(tests[i].expected_group_name, |
| 11258 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11259 | } |
| 11260 | } |
| 11261 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11262 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11263 | HttpRequestInfo request; |
| 11264 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11265 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11266 | request.traffic_annotation = |
| 11267 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11268 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11269 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11270 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11271 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11272 | // This simulates failure resolving all hostnames; that means we will fail |
| 11273 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11274 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11275 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11279 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11280 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11281 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11283 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11284 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11285 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11286 | } |
| 11287 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11288 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 11289 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11290 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11291 | HttpRequestInfo request_info; |
| 11292 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11293 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11294 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11295 | request_info.traffic_annotation = |
| 11296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11297 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 11298 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11299 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11303 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11304 | // 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] | 11305 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11306 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11307 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11308 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11309 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11310 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11311 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11315 | |
| 11316 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 11317 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11318 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11319 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11320 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11321 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11322 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11323 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11324 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11325 | // 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] | 11326 | // we can tell if the next lookup hit the cache, or the "network". |
| 11327 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11328 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11329 | |
| 11330 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 11331 | // 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] | 11332 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11333 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11335 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11336 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11337 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11338 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11339 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11340 | |
| 11341 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11342 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11343 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11344 | } |
| 11345 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11346 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11347 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11348 | HttpRequestInfo request; |
| 11349 | request.method = "GET"; |
| 11350 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11351 | request.traffic_annotation = |
| 11352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11353 | |
| 11354 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11355 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11356 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11357 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11358 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11361 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11363 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11364 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11365 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11367 | |
| 11368 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11369 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11370 | |
| 11371 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11372 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11373 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11374 | } |
| 11375 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11376 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11377 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11378 | HttpRequestInfo request; |
| 11379 | request.method = "GET"; |
| 11380 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11381 | request.traffic_annotation = |
| 11382 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11383 | |
| 11384 | MockRead data_reads[] = { |
| 11385 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11386 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11387 | }; |
| 11388 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11389 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11393 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11396 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11397 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11398 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11399 | |
| 11400 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11401 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11402 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11403 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11404 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11405 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11406 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11407 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11408 | |
| 11409 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11410 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11411 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11412 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11413 | |
| 11414 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11415 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11416 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11417 | } |
| 11418 | |
| 11419 | // Make sure that a dropped connection while draining the body for auth |
| 11420 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11421 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11422 | HttpRequestInfo request; |
| 11423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11424 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11425 | request.traffic_annotation = |
| 11426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11427 | |
| 11428 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11429 | MockWrite( |
| 11430 | "GET / HTTP/1.1\r\n" |
| 11431 | "Host: www.example.org\r\n" |
| 11432 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11433 | }; |
| 11434 | |
| 11435 | MockRead data_reads1[] = { |
| 11436 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11437 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11438 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11439 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11440 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11441 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11442 | }; |
| 11443 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11444 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11445 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11447 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11448 | // be issuing -- the final header line contains the credentials. |
| 11449 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11450 | MockWrite( |
| 11451 | "GET / HTTP/1.1\r\n" |
| 11452 | "Host: www.example.org\r\n" |
| 11453 | "Connection: keep-alive\r\n" |
| 11454 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11455 | }; |
| 11456 | |
| 11457 | // Lastly, the server responds with the actual content. |
| 11458 | MockRead data_reads2[] = { |
| 11459 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11460 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11461 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11462 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11463 | }; |
| 11464 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11465 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11466 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11467 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11469 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11472 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11473 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11475 | |
| 11476 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11479 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11480 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11481 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11483 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11485 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11487 | |
| 11488 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11491 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11492 | ASSERT_TRUE(response); |
| 11493 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11494 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11495 | } |
| 11496 | |
| 11497 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11498 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11499 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11500 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11501 | |
| 11502 | HttpRequestInfo request; |
| 11503 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11504 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11505 | request.traffic_annotation = |
| 11506 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11507 | |
| 11508 | MockRead proxy_reads[] = { |
| 11509 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11510 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11511 | }; |
| 11512 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11513 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11514 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11515 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11516 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11518 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11519 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11520 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11521 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11522 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11525 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11526 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11527 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11528 | |
| 11529 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11530 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11531 | } |
| 11532 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11533 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11534 | HttpRequestInfo request; |
| 11535 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11536 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11537 | request.traffic_annotation = |
| 11538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11542 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11543 | MockRead data_reads[] = { |
| 11544 | 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] | 11545 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11546 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11548 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11549 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11551 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11552 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11553 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11554 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11555 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11556 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11559 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11560 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11561 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11562 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11563 | |
| 11564 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11565 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11566 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11567 | } |
| 11568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11569 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11570 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11571 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11572 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11573 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11574 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11575 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11576 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11577 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11578 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11579 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11580 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11581 | |
| 11582 | HttpRequestInfo request; |
| 11583 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11584 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11585 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11586 | request.traffic_annotation = |
| 11587 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11588 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11591 | |
| 11592 | MockRead data_reads[] = { |
| 11593 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11594 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11595 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11596 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11597 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11600 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11601 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11604 | |
| 11605 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11606 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11607 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11608 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11609 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11610 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11611 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11612 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11613 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11614 | } |
| 11615 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11616 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11617 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11618 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11619 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11620 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11621 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11622 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11623 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11625 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11626 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11627 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11628 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11629 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11630 | |
| 11631 | HttpRequestInfo request; |
| 11632 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11633 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11634 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11635 | request.traffic_annotation = |
| 11636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11637 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11638 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11641 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11642 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11643 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11644 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11645 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11646 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11647 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11649 | |
| 11650 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11651 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11652 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11653 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11654 | } |
| 11655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11656 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11657 | class FakeUploadElementReader : public UploadElementReader { |
| 11658 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11659 | FakeUploadElementReader() = default; |
| 11660 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11661 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11662 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11663 | |
| 11664 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11665 | int Init(CompletionOnceCallback callback) override { |
| 11666 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11667 | return ERR_IO_PENDING; |
| 11668 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11669 | uint64_t GetContentLength() const override { return 0; } |
| 11670 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11671 | int Read(IOBuffer* buf, |
| 11672 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11673 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11674 | return ERR_FAILED; |
| 11675 | } |
| 11676 | |
| 11677 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11678 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11679 | }; |
| 11680 | |
| 11681 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11682 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11683 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11684 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11685 | |
| 11686 | HttpRequestInfo request; |
| 11687 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11688 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11689 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11690 | request.traffic_annotation = |
| 11691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11692 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11693 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11694 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11695 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11696 | |
| 11697 | StaticSocketDataProvider data; |
| 11698 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11699 | |
| 11700 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11701 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11702 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11703 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11704 | |
| 11705 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11706 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11707 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11708 | |
| 11709 | // Return Init()'s result after the transaction gets destroyed. |
| 11710 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11711 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11712 | } |
| 11713 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11714 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11715 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11716 | HttpRequestInfo request; |
| 11717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11718 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11719 | request.traffic_annotation = |
| 11720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11721 | |
| 11722 | // First transaction will request a resource and receive a Basic challenge |
| 11723 | // with realm="first_realm". |
| 11724 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11725 | MockWrite( |
| 11726 | "GET / HTTP/1.1\r\n" |
| 11727 | "Host: www.example.org\r\n" |
| 11728 | "Connection: keep-alive\r\n" |
| 11729 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11730 | }; |
| 11731 | MockRead data_reads1[] = { |
| 11732 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11733 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11734 | "\r\n"), |
| 11735 | }; |
| 11736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11737 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11738 | // for first_realm. The server will reject and provide a challenge with |
| 11739 | // second_realm. |
| 11740 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11741 | MockWrite( |
| 11742 | "GET / HTTP/1.1\r\n" |
| 11743 | "Host: www.example.org\r\n" |
| 11744 | "Connection: keep-alive\r\n" |
| 11745 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11746 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11747 | }; |
| 11748 | MockRead data_reads2[] = { |
| 11749 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11750 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11751 | "\r\n"), |
| 11752 | }; |
| 11753 | |
| 11754 | // This again fails, and goes back to first_realm. Make sure that the |
| 11755 | // entry is removed from cache. |
| 11756 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11757 | MockWrite( |
| 11758 | "GET / HTTP/1.1\r\n" |
| 11759 | "Host: www.example.org\r\n" |
| 11760 | "Connection: keep-alive\r\n" |
| 11761 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11762 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11763 | }; |
| 11764 | MockRead data_reads3[] = { |
| 11765 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11766 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11767 | "\r\n"), |
| 11768 | }; |
| 11769 | |
| 11770 | // Try one last time (with the correct password) and get the resource. |
| 11771 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11772 | MockWrite( |
| 11773 | "GET / HTTP/1.1\r\n" |
| 11774 | "Host: www.example.org\r\n" |
| 11775 | "Connection: keep-alive\r\n" |
| 11776 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11777 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11778 | }; |
| 11779 | MockRead data_reads4[] = { |
| 11780 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11781 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11782 | "Content-Length: 5\r\n" |
| 11783 | "\r\n" |
| 11784 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11785 | }; |
| 11786 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11787 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11788 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11789 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11790 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11791 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11792 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11793 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11794 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11796 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11797 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11799 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11800 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11801 | // Issue the first request with Authorize headers. There should be a |
| 11802 | // password prompt for first_realm waiting to be filled in after the |
| 11803 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11804 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11806 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11807 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11809 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11810 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11811 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11812 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11813 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11814 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11815 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11816 | |
| 11817 | // Issue the second request with an incorrect password. There should be a |
| 11818 | // password prompt for second_realm waiting to be filled in after the |
| 11819 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11820 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11821 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11822 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11824 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11825 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11826 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11827 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11828 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11829 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11830 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11831 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11832 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11833 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11834 | |
| 11835 | // Issue the third request with another incorrect password. There should be |
| 11836 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11837 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11838 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11839 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11840 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11841 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11843 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11844 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11845 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11846 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11847 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11848 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11849 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11850 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11851 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11852 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11853 | |
| 11854 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11855 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11856 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11857 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11859 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11860 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11861 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11862 | ASSERT_TRUE(response); |
| 11863 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11864 | } |
| 11865 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11866 | // Regression test for https://crbug.com/754395. |
| 11867 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11868 | MockRead data_reads[] = { |
| 11869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11870 | MockRead(kAlternativeServiceHttpHeader), |
| 11871 | MockRead("\r\n"), |
| 11872 | MockRead("hello world"), |
| 11873 | MockRead(SYNCHRONOUS, OK), |
| 11874 | }; |
| 11875 | |
| 11876 | HttpRequestInfo request; |
| 11877 | request.method = "GET"; |
| 11878 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11879 | request.traffic_annotation = |
| 11880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11881 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11882 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11884 | |
| 11885 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11886 | ssl.ssl_info.cert = |
| 11887 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11888 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11889 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11891 | |
| 11892 | TestCompletionCallback callback; |
| 11893 | |
| 11894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11895 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11896 | |
| 11897 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11899 | |
| 11900 | url::SchemeHostPort test_server(request.url); |
| 11901 | HttpServerProperties* http_server_properties = |
| 11902 | session->http_server_properties(); |
| 11903 | EXPECT_TRUE( |
| 11904 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11905 | |
| 11906 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11907 | |
| 11908 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11909 | ASSERT_TRUE(response); |
| 11910 | ASSERT_TRUE(response->headers); |
| 11911 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11912 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11913 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11914 | |
| 11915 | std::string response_data; |
| 11916 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11917 | EXPECT_EQ("hello world", response_data); |
| 11918 | |
| 11919 | EXPECT_TRUE( |
| 11920 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11921 | } |
| 11922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11923 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11924 | MockRead data_reads[] = { |
| 11925 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11926 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11927 | MockRead("\r\n"), |
| 11928 | MockRead("hello world"), |
| 11929 | MockRead(SYNCHRONOUS, OK), |
| 11930 | }; |
| 11931 | |
| 11932 | HttpRequestInfo request; |
| 11933 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11934 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11935 | request.traffic_annotation = |
| 11936 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11937 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11938 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11939 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11940 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11941 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11942 | ssl.ssl_info.cert = |
| 11943 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11944 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11945 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11946 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11947 | TestCompletionCallback callback; |
| 11948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11951 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11952 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11953 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11954 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11955 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11956 | HttpServerProperties* http_server_properties = |
| 11957 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11958 | EXPECT_TRUE( |
| 11959 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11960 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11961 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11963 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11964 | ASSERT_TRUE(response); |
| 11965 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11966 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11967 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11968 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11969 | |
| 11970 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11971 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11972 | EXPECT_EQ("hello world", response_data); |
| 11973 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11974 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11975 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11976 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11977 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11978 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11979 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11980 | } |
| 11981 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11982 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11983 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11984 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11985 | MockRead data_reads[] = { |
| 11986 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11987 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11988 | MockRead("\r\n"), |
| 11989 | MockRead("hello world"), |
| 11990 | MockRead(SYNCHRONOUS, OK), |
| 11991 | }; |
| 11992 | |
| 11993 | HttpRequestInfo request; |
| 11994 | request.method = "GET"; |
| 11995 | request.url = GURL("http://www.example.org/"); |
| 11996 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11997 | request.traffic_annotation = |
| 11998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11999 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12000 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12001 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12002 | |
| 12003 | TestCompletionCallback callback; |
| 12004 | |
| 12005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12006 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12007 | |
| 12008 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12009 | HttpServerProperties* http_server_properties = |
| 12010 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12011 | EXPECT_TRUE( |
| 12012 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12013 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12014 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12016 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12018 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12019 | ASSERT_TRUE(response); |
| 12020 | ASSERT_TRUE(response->headers); |
| 12021 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12022 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12023 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12024 | |
| 12025 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12026 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12027 | EXPECT_EQ("hello world", response_data); |
| 12028 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12029 | EXPECT_TRUE( |
| 12030 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12031 | } |
| 12032 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12033 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12034 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12035 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12036 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12037 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12038 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12039 | HttpRequestInfo request; |
| 12040 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12041 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12042 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12043 | request.traffic_annotation = |
| 12044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12045 | |
| 12046 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12047 | StaticSocketDataProvider first_data; |
| 12048 | first_data.set_connect_data(mock_connect); |
| 12049 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12050 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12051 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12053 | |
| 12054 | MockRead data_reads[] = { |
| 12055 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12056 | MockRead(ASYNC, OK), |
| 12057 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12058 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12059 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12060 | |
| 12061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12062 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12063 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12064 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12065 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12066 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12067 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12068 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12069 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12072 | TestCompletionCallback callback; |
| 12073 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12074 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12075 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12076 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12077 | } |
| 12078 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12079 | // Regression test for https://crbug.com/615497: |
| 12080 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12081 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12082 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12083 | HttpRequestInfo request; |
| 12084 | request.method = "GET"; |
| 12085 | request.url = GURL("http://www.example.org/"); |
| 12086 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12087 | request.traffic_annotation = |
| 12088 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12089 | |
| 12090 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12091 | StaticSocketDataProvider first_data; |
| 12092 | first_data.set_connect_data(mock_connect); |
| 12093 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12094 | |
| 12095 | MockRead data_reads[] = { |
| 12096 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12097 | MockRead(ASYNC, OK), |
| 12098 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12099 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12100 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12101 | |
| 12102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12103 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12104 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12105 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12106 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12107 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12108 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12109 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12111 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12112 | TestCompletionCallback callback; |
| 12113 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12114 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12115 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12116 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12117 | } |
| 12118 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12119 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12120 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12121 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12122 | HttpServerProperties* http_server_properties = |
| 12123 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12124 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12125 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12126 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12127 | http_server_properties->SetQuicAlternativeService( |
| 12128 | test_server, alternative_service, expiration, |
| 12129 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12130 | EXPECT_EQ( |
| 12131 | 1u, |
| 12132 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12133 | |
| 12134 | // Send a clear header. |
| 12135 | MockRead data_reads[] = { |
| 12136 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12137 | MockRead("Alt-Svc: clear\r\n"), |
| 12138 | MockRead("\r\n"), |
| 12139 | MockRead("hello world"), |
| 12140 | MockRead(SYNCHRONOUS, OK), |
| 12141 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12142 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12144 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12145 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12146 | ssl.ssl_info.cert = |
| 12147 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12148 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12150 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12151 | HttpRequestInfo request; |
| 12152 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12153 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12154 | request.traffic_annotation = |
| 12155 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12156 | |
| 12157 | TestCompletionCallback callback; |
| 12158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12160 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12161 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12162 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12164 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12165 | ASSERT_TRUE(response); |
| 12166 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12167 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12168 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12169 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12170 | |
| 12171 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12172 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12173 | EXPECT_EQ("hello world", response_data); |
| 12174 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12175 | EXPECT_TRUE( |
| 12176 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12177 | } |
| 12178 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12179 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12180 | MockRead data_reads[] = { |
| 12181 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12182 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12183 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12184 | MockRead("hello world"), |
| 12185 | MockRead(SYNCHRONOUS, OK), |
| 12186 | }; |
| 12187 | |
| 12188 | HttpRequestInfo request; |
| 12189 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12190 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12191 | request.traffic_annotation = |
| 12192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12193 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12194 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12195 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12196 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12197 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12198 | ssl.ssl_info.cert = |
| 12199 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12200 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12202 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12203 | TestCompletionCallback callback; |
| 12204 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12206 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12207 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12208 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12210 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12211 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12212 | HttpServerProperties* http_server_properties = |
| 12213 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12214 | EXPECT_TRUE( |
| 12215 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12216 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12217 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12219 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12220 | ASSERT_TRUE(response); |
| 12221 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12222 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12223 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12224 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12225 | |
| 12226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12227 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12228 | EXPECT_EQ("hello world", response_data); |
| 12229 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12230 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12231 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12232 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12233 | |
| 12234 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12235 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12236 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12237 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12238 | 1234); |
| 12239 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12240 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12241 | } |
| 12242 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12243 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12244 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12245 | HostPortPair alternative("alternative.example.org", 443); |
| 12246 | std::string origin_url = "https://origin.example.org:443"; |
| 12247 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12248 | |
| 12249 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12250 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12251 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12252 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12253 | |
| 12254 | // HTTP/1.1 data for request. |
| 12255 | MockWrite http_writes[] = { |
| 12256 | MockWrite("GET / HTTP/1.1\r\n" |
| 12257 | "Host: alternative.example.org\r\n" |
| 12258 | "Connection: keep-alive\r\n\r\n"), |
| 12259 | }; |
| 12260 | |
| 12261 | MockRead http_reads[] = { |
| 12262 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12263 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12264 | "Content-Length: 40\r\n\r\n" |
| 12265 | "first HTTP/1.1 response from alternative"), |
| 12266 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12267 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12268 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12269 | |
| 12270 | StaticSocketDataProvider data_refused; |
| 12271 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12272 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12273 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12274 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12276 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12277 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12278 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12279 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12280 | http_server_properties->SetQuicAlternativeService( |
| 12281 | server, alternative_service, expiration, |
| 12282 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12283 | // Mark the QUIC alternative service as broken. |
| 12284 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12285 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12286 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12288 | request.method = "GET"; |
| 12289 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12290 | request.traffic_annotation = |
| 12291 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12292 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12293 | TestCompletionCallback callback; |
| 12294 | NetErrorDetails details; |
| 12295 | EXPECT_FALSE(details.quic_broken); |
| 12296 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12297 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12298 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12299 | EXPECT_TRUE(details.quic_broken); |
| 12300 | } |
| 12301 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12302 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12303 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12304 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12305 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12306 | std::string origin_url = "https://origin.example.org:443"; |
| 12307 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12308 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12309 | |
| 12310 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12311 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12312 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12314 | |
| 12315 | // HTTP/1.1 data for request. |
| 12316 | MockWrite http_writes[] = { |
| 12317 | MockWrite("GET / HTTP/1.1\r\n" |
| 12318 | "Host: alternative1.example.org\r\n" |
| 12319 | "Connection: keep-alive\r\n\r\n"), |
| 12320 | }; |
| 12321 | |
| 12322 | MockRead http_reads[] = { |
| 12323 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12324 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12325 | "Content-Length: 40\r\n\r\n" |
| 12326 | "first HTTP/1.1 response from alternative1"), |
| 12327 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12328 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12329 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12330 | |
| 12331 | StaticSocketDataProvider data_refused; |
| 12332 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12333 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12334 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12336 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12337 | session->http_server_properties(); |
| 12338 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12339 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12340 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12341 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12342 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12343 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12344 | alternative_service_info_vector.push_back( |
| 12345 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12346 | alternative_service1, expiration, |
| 12347 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12348 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12349 | alternative_service_info_vector.push_back( |
| 12350 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12351 | alternative_service2, expiration, |
| 12352 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12353 | |
| 12354 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12355 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12356 | |
| 12357 | // Mark one of the QUIC alternative service as broken. |
| 12358 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12359 | EXPECT_EQ(2u, |
| 12360 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12361 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12362 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12363 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12364 | request.method = "GET"; |
| 12365 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12366 | request.traffic_annotation = |
| 12367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12368 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12369 | TestCompletionCallback callback; |
| 12370 | NetErrorDetails details; |
| 12371 | EXPECT_FALSE(details.quic_broken); |
| 12372 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12373 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12374 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12375 | EXPECT_FALSE(details.quic_broken); |
| 12376 | } |
| 12377 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12378 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12379 | HttpRequestInfo request; |
| 12380 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12381 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12382 | request.traffic_annotation = |
| 12383 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12384 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12385 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12386 | StaticSocketDataProvider first_data; |
| 12387 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12388 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12389 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12390 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12392 | |
| 12393 | MockRead data_reads[] = { |
| 12394 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12395 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12396 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12397 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12398 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12399 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12400 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12402 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12403 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12404 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12405 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12406 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12407 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12408 | // Port is ignored by MockConnect anyway. |
| 12409 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12410 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12411 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12412 | http_server_properties->SetHttp2AlternativeService( |
| 12413 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12415 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12416 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12417 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12418 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12420 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12421 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12422 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12423 | ASSERT_TRUE(response); |
| 12424 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12425 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12426 | |
| 12427 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12428 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12429 | EXPECT_EQ("hello world", response_data); |
| 12430 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12431 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12432 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12433 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12434 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12435 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12436 | EXPECT_TRUE( |
| 12437 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12438 | } |
| 12439 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12440 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12441 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12442 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12443 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12444 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12445 | HttpRequestInfo restricted_port_request; |
| 12446 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12447 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12448 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12449 | restricted_port_request.traffic_annotation = |
| 12450 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12451 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12452 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12453 | StaticSocketDataProvider first_data; |
| 12454 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12455 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12456 | |
| 12457 | MockRead data_reads[] = { |
| 12458 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12459 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12460 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12461 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12462 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12463 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12464 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12465 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12467 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12469 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12470 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12471 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12472 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12473 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12474 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12475 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12476 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12477 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12478 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12480 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12481 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12482 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12483 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12484 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12486 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12487 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12488 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12489 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12490 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12491 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12492 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12493 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12494 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12495 | |
| 12496 | HttpRequestInfo restricted_port_request; |
| 12497 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12498 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12499 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12500 | restricted_port_request.traffic_annotation = |
| 12501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12502 | |
| 12503 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12504 | StaticSocketDataProvider first_data; |
| 12505 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12506 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12507 | |
| 12508 | MockRead data_reads[] = { |
| 12509 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12510 | MockRead("hello world"), |
| 12511 | MockRead(ASYNC, OK), |
| 12512 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12513 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12514 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12515 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12516 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12518 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12519 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12520 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12521 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12522 | session->http_server_properties(); |
| 12523 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12524 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12525 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12526 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12527 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12528 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12529 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12531 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12532 | TestCompletionCallback callback; |
| 12533 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12534 | EXPECT_EQ(ERR_IO_PENDING, |
| 12535 | trans.Start(&restricted_port_request, callback.callback(), |
| 12536 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12537 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12538 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12539 | } |
| 12540 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12541 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12542 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12543 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12544 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12545 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12546 | HttpRequestInfo restricted_port_request; |
| 12547 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12548 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12549 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12550 | restricted_port_request.traffic_annotation = |
| 12551 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12552 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12553 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12554 | StaticSocketDataProvider first_data; |
| 12555 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12556 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12557 | |
| 12558 | MockRead data_reads[] = { |
| 12559 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12560 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12561 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12562 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12563 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12564 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12565 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12566 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12568 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12570 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12571 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12572 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12573 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12574 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12575 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12576 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12577 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12578 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12579 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12582 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12583 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12584 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12585 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12587 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12588 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12589 | } |
| 12590 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12591 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12592 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12593 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12594 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12595 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12596 | HttpRequestInfo unrestricted_port_request; |
| 12597 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12598 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12599 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12600 | unrestricted_port_request.traffic_annotation = |
| 12601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12602 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12603 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12604 | StaticSocketDataProvider first_data; |
| 12605 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12606 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12607 | |
| 12608 | MockRead data_reads[] = { |
| 12609 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12610 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12611 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12612 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12613 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12614 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12615 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12616 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12618 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12620 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12621 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12622 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12623 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12624 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12625 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12626 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12627 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12628 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12629 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12631 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12632 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12634 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12635 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12637 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12638 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12639 | } |
| 12640 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12641 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12642 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12643 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12644 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12645 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12646 | HttpRequestInfo unrestricted_port_request; |
| 12647 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12648 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12649 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12650 | unrestricted_port_request.traffic_annotation = |
| 12651 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12652 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12653 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12654 | StaticSocketDataProvider first_data; |
| 12655 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12656 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12657 | |
| 12658 | MockRead data_reads[] = { |
| 12659 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12660 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12661 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12662 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12663 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12664 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12665 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12666 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12668 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12670 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12671 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12672 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12673 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12674 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12675 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12676 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12677 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12678 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12679 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12681 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12682 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12684 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12685 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12687 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12688 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12689 | } |
| 12690 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12691 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12692 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12693 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12694 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12695 | HttpRequestInfo request; |
| 12696 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12697 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12698 | request.traffic_annotation = |
| 12699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12700 | |
| 12701 | // The alternate protocol request will error out before we attempt to connect, |
| 12702 | // so only the standard HTTP request will try to connect. |
| 12703 | MockRead data_reads[] = { |
| 12704 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12705 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12706 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12707 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12708 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12710 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12711 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12712 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12713 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12714 | session->http_server_properties(); |
| 12715 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12716 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12717 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12718 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12719 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12720 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12722 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12723 | TestCompletionCallback callback; |
| 12724 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12725 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12727 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12728 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12730 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12731 | ASSERT_TRUE(response); |
| 12732 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12733 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12734 | |
| 12735 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12736 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12737 | EXPECT_EQ("hello world", response_data); |
| 12738 | } |
| 12739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12740 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12741 | HttpRequestInfo request; |
| 12742 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12743 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12744 | request.traffic_annotation = |
| 12745 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12746 | |
| 12747 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12748 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12749 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12750 | MockRead("\r\n"), |
| 12751 | MockRead("hello world"), |
| 12752 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12753 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12754 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12755 | StaticSocketDataProvider first_transaction(data_reads, |
| 12756 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12757 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12758 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12759 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12761 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12762 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12763 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12764 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12765 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12766 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12767 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12768 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12769 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12770 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12771 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12772 | }; |
| 12773 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12774 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12775 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12776 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12777 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12778 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12779 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12780 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12781 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12782 | &hanging_non_alternate_protocol_socket); |
| 12783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12784 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12787 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12788 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12789 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12790 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12792 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12793 | |
| 12794 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12795 | ASSERT_TRUE(response); |
| 12796 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12797 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12798 | |
| 12799 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12800 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12801 | EXPECT_EQ("hello world", response_data); |
| 12802 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12803 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12804 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12805 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12806 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12808 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12809 | |
| 12810 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12811 | ASSERT_TRUE(response); |
| 12812 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12813 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12814 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12815 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12816 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12817 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12818 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12819 | } |
| 12820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12821 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12822 | HttpRequestInfo request; |
| 12823 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12824 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12825 | request.traffic_annotation = |
| 12826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12827 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12828 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12829 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12830 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12831 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12832 | MockRead("\r\n"), |
| 12833 | MockRead("hello world"), |
| 12834 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12835 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12836 | }; |
| 12837 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12838 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12839 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12840 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12841 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12842 | ssl_http11.ssl_info.cert = |
| 12843 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12844 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12845 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12846 | |
| 12847 | // Second transaction starts an alternative and a non-alternative Job. |
| 12848 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12849 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12850 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12851 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12852 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12854 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12855 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12856 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12857 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12858 | // Third transaction starts an alternative and a non-alternative job. |
| 12859 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12860 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12861 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12862 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12863 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12864 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12865 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12866 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12867 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12868 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12869 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12870 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 12871 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12872 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12873 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12874 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12875 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12876 | }; |
| 12877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12878 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12879 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12880 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12881 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12883 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12884 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12885 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12886 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12888 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12889 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12890 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12891 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12893 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12894 | |
| 12895 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12896 | ASSERT_TRUE(response); |
| 12897 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12898 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12899 | |
| 12900 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12901 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12902 | EXPECT_EQ("hello world", response_data); |
| 12903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12904 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12905 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12906 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12909 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12910 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12911 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12913 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12914 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12915 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12916 | |
| 12917 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12918 | ASSERT_TRUE(response); |
| 12919 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12920 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12921 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12922 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12923 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12924 | EXPECT_EQ("hello!", response_data); |
| 12925 | |
| 12926 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12927 | ASSERT_TRUE(response); |
| 12928 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12929 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12930 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12931 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12932 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12933 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12934 | } |
| 12935 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12936 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12937 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12938 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12939 | HttpRequestInfo request; |
| 12940 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12941 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12942 | request.traffic_annotation = |
| 12943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12944 | |
| 12945 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12946 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12947 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12948 | MockRead("\r\n"), |
| 12949 | MockRead("hello world"), |
| 12950 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12951 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12952 | }; |
| 12953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12954 | StaticSocketDataProvider first_transaction(data_reads, |
| 12955 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12956 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12957 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12958 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12959 | ssl.ssl_info.cert = |
| 12960 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12961 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12963 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12964 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12965 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12966 | hanging_alternate_protocol_socket.set_connect_data( |
| 12967 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12968 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12969 | &hanging_alternate_protocol_socket); |
| 12970 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12971 | // 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] | 12972 | StaticSocketDataProvider second_transaction(data_reads, |
| 12973 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12974 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12975 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12977 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12980 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12981 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12982 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12983 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12984 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12985 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12986 | |
| 12987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12988 | ASSERT_TRUE(response); |
| 12989 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12990 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12991 | |
| 12992 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12993 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12994 | EXPECT_EQ("hello world", response_data); |
| 12995 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12996 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12997 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12998 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12999 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13001 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13002 | |
| 13003 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13004 | ASSERT_TRUE(response); |
| 13005 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13006 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13007 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13008 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13009 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13010 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13011 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13012 | } |
| 13013 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13014 | // Test that proxy is resolved using the origin url, |
| 13015 | // regardless of the alternative server. |
| 13016 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13017 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13018 | ProxyConfig proxy_config; |
| 13019 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13020 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13021 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13022 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13023 | |
| 13024 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13025 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13026 | &capturing_proxy_resolver); |
| 13027 | |
| 13028 | TestNetLog net_log; |
| 13029 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13030 | session_deps_.proxy_resolution_service = |
| 13031 | std::make_unique<ProxyResolutionService>( |
| 13032 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13033 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13034 | |
| 13035 | session_deps_.net_log = &net_log; |
| 13036 | |
| 13037 | // Configure alternative service with a hostname that is not bypassed by the |
| 13038 | // proxy. |
| 13039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13040 | HttpServerProperties* http_server_properties = |
| 13041 | session->http_server_properties(); |
| 13042 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13043 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13044 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13045 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13046 | http_server_properties->SetHttp2AlternativeService( |
| 13047 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13048 | |
| 13049 | // Non-alternative job should hang. |
| 13050 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13051 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13052 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13053 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13054 | &hanging_alternate_protocol_socket); |
| 13055 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13056 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13057 | |
| 13058 | HttpRequestInfo request; |
| 13059 | request.method = "GET"; |
| 13060 | request.url = GURL("https://www.example.org/"); |
| 13061 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13062 | request.traffic_annotation = |
| 13063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13064 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13065 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13066 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13067 | |
| 13068 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13069 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13070 | spdy::SpdySerializedFrame resp( |
| 13071 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13072 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13073 | MockRead spdy_reads[] = { |
| 13074 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13075 | }; |
| 13076 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13077 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13078 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13079 | |
| 13080 | TestCompletionCallback callback; |
| 13081 | |
| 13082 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13083 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13084 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13085 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13086 | |
| 13087 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13088 | ASSERT_TRUE(response); |
| 13089 | ASSERT_TRUE(response->headers); |
| 13090 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13091 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13092 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13093 | |
| 13094 | std::string response_data; |
| 13095 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13096 | EXPECT_EQ("hello!", response_data); |
| 13097 | |
| 13098 | // Origin host bypasses proxy, no resolution should have happened. |
| 13099 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13100 | } |
| 13101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13102 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13103 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13104 | proxy_config.set_auto_detect(true); |
| 13105 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13106 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13107 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13108 | session_deps_.proxy_resolution_service = |
| 13109 | std::make_unique<ProxyResolutionService>( |
| 13110 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13111 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13112 | std::make_unique<CapturingProxyResolverFactory>( |
| 13113 | &capturing_proxy_resolver), |
| 13114 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13115 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13116 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13117 | |
| 13118 | HttpRequestInfo request; |
| 13119 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13120 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13121 | request.traffic_annotation = |
| 13122 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13123 | |
| 13124 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13125 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13126 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13127 | MockRead("\r\n"), |
| 13128 | MockRead("hello world"), |
| 13129 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13130 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13131 | }; |
| 13132 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13133 | StaticSocketDataProvider first_transaction(data_reads, |
| 13134 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13135 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13136 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13137 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13138 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13139 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13140 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13141 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13142 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13143 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13144 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13145 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13146 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13147 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13148 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13149 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13150 | }; |
| 13151 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13152 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13153 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13154 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13155 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13156 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13157 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13158 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13159 | }; |
| 13160 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13161 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13162 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13163 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13164 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13165 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13166 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13167 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13168 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13169 | &hanging_non_alternate_protocol_socket); |
| 13170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13171 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13172 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13174 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13175 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13176 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13177 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13179 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13180 | |
| 13181 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13182 | ASSERT_TRUE(response); |
| 13183 | ASSERT_TRUE(response->headers); |
| 13184 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13185 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13186 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13187 | |
| 13188 | std::string response_data; |
| 13189 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13190 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13191 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13192 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13193 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13195 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13197 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13198 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13199 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13200 | ASSERT_TRUE(response); |
| 13201 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13202 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13203 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13204 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13205 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13206 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13207 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13208 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13209 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13210 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13211 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13212 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13213 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13214 | LoadTimingInfo load_timing_info; |
| 13215 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13216 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13217 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13218 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13219 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13220 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13221 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13222 | HttpRequestInfo request; |
| 13223 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13224 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13225 | request.traffic_annotation = |
| 13226 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13227 | |
| 13228 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13229 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13230 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13231 | MockRead("\r\n"), |
| 13232 | MockRead("hello world"), |
| 13233 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13234 | }; |
| 13235 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13236 | StaticSocketDataProvider first_transaction(data_reads, |
| 13237 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13238 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13239 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13240 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13241 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13242 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13243 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13244 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13245 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13246 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13247 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13248 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13249 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13250 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13251 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13252 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13253 | }; |
| 13254 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13255 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13256 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13257 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13258 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13259 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13261 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13262 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13263 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13264 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13265 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13267 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13268 | |
| 13269 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13270 | ASSERT_TRUE(response); |
| 13271 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13272 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13273 | |
| 13274 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13275 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13276 | EXPECT_EQ("hello world", response_data); |
| 13277 | |
| 13278 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13279 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13280 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13281 | PRIVACY_MODE_DISABLED, |
| 13282 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13283 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13284 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13285 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13286 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13287 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13288 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13289 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13290 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13291 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13292 | |
| 13293 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13294 | ASSERT_TRUE(response); |
| 13295 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13296 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13297 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13298 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13299 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13300 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13301 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13302 | } |
| 13303 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13304 | // GenerateAuthToken is a mighty big test. |
| 13305 | // It tests all permutation of GenerateAuthToken behavior: |
| 13306 | // - Synchronous and Asynchronous completion. |
| 13307 | // - OK or error on completion. |
| 13308 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13309 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13310 | // - Non-authenticating and authenticating backend. |
| 13311 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13312 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13313 | // problems generating an auth token for an authenticating proxy, we don't |
| 13314 | // need to test all permutations of the backend server). |
| 13315 | // |
| 13316 | // The test proceeds by going over each of the configuration cases, and |
| 13317 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13318 | // specifies both the configuration for the test as well as the expectations |
| 13319 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13320 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13321 | static const char kServer[] = "http://www.example.com"; |
| 13322 | static const char kSecureServer[] = "https://www.example.com"; |
| 13323 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13324 | |
| 13325 | enum AuthTiming { |
| 13326 | AUTH_NONE, |
| 13327 | AUTH_SYNC, |
| 13328 | AUTH_ASYNC, |
| 13329 | }; |
| 13330 | |
| 13331 | const MockWrite kGet( |
| 13332 | "GET / HTTP/1.1\r\n" |
| 13333 | "Host: www.example.com\r\n" |
| 13334 | "Connection: keep-alive\r\n\r\n"); |
| 13335 | const MockWrite kGetProxy( |
| 13336 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13337 | "Host: www.example.com\r\n" |
| 13338 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13339 | const MockWrite kGetAuth( |
| 13340 | "GET / HTTP/1.1\r\n" |
| 13341 | "Host: www.example.com\r\n" |
| 13342 | "Connection: keep-alive\r\n" |
| 13343 | "Authorization: auth_token\r\n\r\n"); |
| 13344 | const MockWrite kGetProxyAuth( |
| 13345 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13346 | "Host: www.example.com\r\n" |
| 13347 | "Proxy-Connection: keep-alive\r\n" |
| 13348 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13349 | const MockWrite kGetAuthThroughProxy( |
| 13350 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13351 | "Host: www.example.com\r\n" |
| 13352 | "Proxy-Connection: keep-alive\r\n" |
| 13353 | "Authorization: auth_token\r\n\r\n"); |
| 13354 | const MockWrite kGetAuthWithProxyAuth( |
| 13355 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13356 | "Host: www.example.com\r\n" |
| 13357 | "Proxy-Connection: keep-alive\r\n" |
| 13358 | "Proxy-Authorization: auth_token\r\n" |
| 13359 | "Authorization: auth_token\r\n\r\n"); |
| 13360 | const MockWrite kConnect( |
| 13361 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13362 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13363 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13364 | const MockWrite kConnectProxyAuth( |
| 13365 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13366 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13367 | "Proxy-Connection: keep-alive\r\n" |
| 13368 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13369 | |
| 13370 | const MockRead kSuccess( |
| 13371 | "HTTP/1.1 200 OK\r\n" |
| 13372 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13373 | "Content-Length: 3\r\n\r\n" |
| 13374 | "Yes"); |
| 13375 | const MockRead kFailure( |
| 13376 | "Should not be called."); |
| 13377 | const MockRead kServerChallenge( |
| 13378 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13379 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13380 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13381 | "Content-Length: 14\r\n\r\n" |
| 13382 | "Unauthorized\r\n"); |
| 13383 | const MockRead kProxyChallenge( |
| 13384 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13385 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13386 | "Proxy-Connection: close\r\n" |
| 13387 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13388 | "Content-Length: 14\r\n\r\n" |
| 13389 | "Unauthorized\r\n"); |
| 13390 | const MockRead kProxyConnected( |
| 13391 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13392 | |
| 13393 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13394 | // no constructors, but the C++ compiler on Windows warns about |
| 13395 | // unspecified data in compound literals. So, moved to using constructors, |
| 13396 | // and TestRound's created with the default constructor should not be used. |
| 13397 | struct TestRound { |
| 13398 | TestRound() |
| 13399 | : expected_rv(ERR_UNEXPECTED), |
| 13400 | extra_write(NULL), |
| 13401 | extra_read(NULL) { |
| 13402 | } |
| 13403 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13404 | int expected_rv_arg) |
| 13405 | : write(write_arg), |
| 13406 | read(read_arg), |
| 13407 | expected_rv(expected_rv_arg), |
| 13408 | extra_write(NULL), |
| 13409 | extra_read(NULL) { |
| 13410 | } |
| 13411 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13412 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13413 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13414 | : write(write_arg), |
| 13415 | read(read_arg), |
| 13416 | expected_rv(expected_rv_arg), |
| 13417 | extra_write(extra_write_arg), |
| 13418 | extra_read(extra_read_arg) { |
| 13419 | } |
| 13420 | MockWrite write; |
| 13421 | MockRead read; |
| 13422 | int expected_rv; |
| 13423 | const MockWrite* extra_write; |
| 13424 | const MockRead* extra_read; |
| 13425 | }; |
| 13426 | |
| 13427 | static const int kNoSSL = 500; |
| 13428 | |
| 13429 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13430 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13431 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13432 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13433 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13434 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13435 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13436 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13437 | int num_auth_rounds; |
| 13438 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13439 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13440 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13441 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13442 | {__LINE__, |
| 13443 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13444 | AUTH_NONE, |
| 13445 | OK, |
| 13446 | kServer, |
| 13447 | AUTH_NONE, |
| 13448 | OK, |
| 13449 | 1, |
| 13450 | kNoSSL, |
| 13451 | {TestRound(kGet, kSuccess, OK)}}, |
| 13452 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13453 | {__LINE__, |
| 13454 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13455 | AUTH_NONE, |
| 13456 | OK, |
| 13457 | kServer, |
| 13458 | AUTH_SYNC, |
| 13459 | OK, |
| 13460 | 2, |
| 13461 | kNoSSL, |
| 13462 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13463 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13464 | {__LINE__, |
| 13465 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13466 | AUTH_NONE, |
| 13467 | OK, |
| 13468 | kServer, |
| 13469 | AUTH_SYNC, |
| 13470 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13471 | 3, |
| 13472 | kNoSSL, |
| 13473 | {TestRound(kGet, kServerChallenge, OK), |
| 13474 | TestRound(kGet, kServerChallenge, OK), |
| 13475 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13476 | {__LINE__, |
| 13477 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13478 | AUTH_NONE, |
| 13479 | OK, |
| 13480 | kServer, |
| 13481 | AUTH_SYNC, |
| 13482 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13483 | 2, |
| 13484 | kNoSSL, |
| 13485 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13486 | {__LINE__, |
| 13487 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13488 | AUTH_NONE, |
| 13489 | OK, |
| 13490 | kServer, |
| 13491 | AUTH_SYNC, |
| 13492 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13493 | 2, |
| 13494 | kNoSSL, |
| 13495 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13496 | {__LINE__, |
| 13497 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13498 | AUTH_SYNC, |
| 13499 | ERR_FAILED, |
| 13500 | kServer, |
| 13501 | AUTH_NONE, |
| 13502 | OK, |
| 13503 | 2, |
| 13504 | kNoSSL, |
| 13505 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13506 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13507 | {__LINE__, |
| 13508 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13509 | AUTH_ASYNC, |
| 13510 | ERR_FAILED, |
| 13511 | kServer, |
| 13512 | AUTH_NONE, |
| 13513 | OK, |
| 13514 | 2, |
| 13515 | kNoSSL, |
| 13516 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13517 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13518 | {__LINE__, |
| 13519 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13520 | AUTH_NONE, |
| 13521 | OK, |
| 13522 | kServer, |
| 13523 | AUTH_SYNC, |
| 13524 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13525 | 2, |
| 13526 | kNoSSL, |
| 13527 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13528 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13529 | {__LINE__, |
| 13530 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13531 | AUTH_NONE, |
| 13532 | OK, |
| 13533 | kServer, |
| 13534 | AUTH_ASYNC, |
| 13535 | ERR_FAILED, |
| 13536 | 2, |
| 13537 | kNoSSL, |
| 13538 | {TestRound(kGet, kServerChallenge, OK), |
| 13539 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13540 | {__LINE__, |
| 13541 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13542 | AUTH_NONE, |
| 13543 | OK, |
| 13544 | kServer, |
| 13545 | AUTH_ASYNC, |
| 13546 | OK, |
| 13547 | 2, |
| 13548 | kNoSSL, |
| 13549 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13550 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13551 | {__LINE__, |
| 13552 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13553 | AUTH_NONE, |
| 13554 | OK, |
| 13555 | kServer, |
| 13556 | AUTH_ASYNC, |
| 13557 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13558 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13559 | kNoSSL, |
| 13560 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13561 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13562 | TestRound(kGet, kServerChallenge, OK), |
| 13563 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13564 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13565 | {__LINE__, |
| 13566 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13567 | AUTH_NONE, |
| 13568 | OK, |
| 13569 | kServer, |
| 13570 | AUTH_NONE, |
| 13571 | OK, |
| 13572 | 1, |
| 13573 | kNoSSL, |
| 13574 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13575 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13576 | {__LINE__, |
| 13577 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13578 | AUTH_NONE, |
| 13579 | OK, |
| 13580 | kServer, |
| 13581 | AUTH_SYNC, |
| 13582 | OK, |
| 13583 | 2, |
| 13584 | kNoSSL, |
| 13585 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13586 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13587 | {__LINE__, |
| 13588 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13589 | AUTH_NONE, |
| 13590 | OK, |
| 13591 | kServer, |
| 13592 | AUTH_SYNC, |
| 13593 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13594 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13595 | kNoSSL, |
| 13596 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13597 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13598 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13599 | {__LINE__, |
| 13600 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13601 | AUTH_NONE, |
| 13602 | OK, |
| 13603 | kServer, |
| 13604 | AUTH_ASYNC, |
| 13605 | OK, |
| 13606 | 2, |
| 13607 | kNoSSL, |
| 13608 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13609 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13610 | {__LINE__, |
| 13611 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13612 | AUTH_NONE, |
| 13613 | OK, |
| 13614 | kServer, |
| 13615 | AUTH_ASYNC, |
| 13616 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13617 | 2, |
| 13618 | kNoSSL, |
| 13619 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13620 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13621 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13622 | {__LINE__, |
| 13623 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13624 | AUTH_SYNC, |
| 13625 | OK, |
| 13626 | kServer, |
| 13627 | AUTH_NONE, |
| 13628 | OK, |
| 13629 | 2, |
| 13630 | kNoSSL, |
| 13631 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13632 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13633 | {__LINE__, |
| 13634 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13635 | AUTH_SYNC, |
| 13636 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13637 | kServer, |
| 13638 | AUTH_NONE, |
| 13639 | OK, |
| 13640 | 2, |
| 13641 | kNoSSL, |
| 13642 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13643 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13644 | {__LINE__, |
| 13645 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13646 | AUTH_ASYNC, |
| 13647 | OK, |
| 13648 | kServer, |
| 13649 | AUTH_NONE, |
| 13650 | OK, |
| 13651 | 2, |
| 13652 | kNoSSL, |
| 13653 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13654 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13655 | {__LINE__, |
| 13656 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13657 | AUTH_ASYNC, |
| 13658 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13659 | kServer, |
| 13660 | AUTH_NONE, |
| 13661 | OK, |
| 13662 | 2, |
| 13663 | kNoSSL, |
| 13664 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13665 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13666 | {__LINE__, |
| 13667 | kProxy, |
| 13668 | AUTH_ASYNC, |
| 13669 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13670 | kServer, |
| 13671 | AUTH_NONE, |
| 13672 | OK, |
| 13673 | 3, |
| 13674 | kNoSSL, |
| 13675 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13676 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13677 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13678 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13679 | {__LINE__, |
| 13680 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13681 | AUTH_SYNC, |
| 13682 | OK, |
| 13683 | kServer, |
| 13684 | AUTH_SYNC, |
| 13685 | OK, |
| 13686 | 3, |
| 13687 | kNoSSL, |
| 13688 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13689 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13690 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13691 | {__LINE__, |
| 13692 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13693 | AUTH_SYNC, |
| 13694 | OK, |
| 13695 | kServer, |
| 13696 | AUTH_SYNC, |
| 13697 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13698 | 3, |
| 13699 | kNoSSL, |
| 13700 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13701 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13702 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13703 | {__LINE__, |
| 13704 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13705 | AUTH_ASYNC, |
| 13706 | OK, |
| 13707 | kServer, |
| 13708 | AUTH_SYNC, |
| 13709 | OK, |
| 13710 | 3, |
| 13711 | kNoSSL, |
| 13712 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13713 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13714 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13715 | {__LINE__, |
| 13716 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13717 | AUTH_ASYNC, |
| 13718 | OK, |
| 13719 | kServer, |
| 13720 | AUTH_SYNC, |
| 13721 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13722 | 3, |
| 13723 | kNoSSL, |
| 13724 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13725 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13726 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13727 | {__LINE__, |
| 13728 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13729 | AUTH_SYNC, |
| 13730 | OK, |
| 13731 | kServer, |
| 13732 | AUTH_ASYNC, |
| 13733 | OK, |
| 13734 | 3, |
| 13735 | kNoSSL, |
| 13736 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13737 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13738 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13739 | {__LINE__, |
| 13740 | kProxy, |
| 13741 | AUTH_SYNC, |
| 13742 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13743 | kServer, |
| 13744 | AUTH_ASYNC, |
| 13745 | OK, |
| 13746 | 4, |
| 13747 | kNoSSL, |
| 13748 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13749 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13750 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13751 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13752 | {__LINE__, |
| 13753 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13754 | AUTH_SYNC, |
| 13755 | OK, |
| 13756 | kServer, |
| 13757 | AUTH_ASYNC, |
| 13758 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13759 | 3, |
| 13760 | kNoSSL, |
| 13761 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13762 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13763 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13764 | {__LINE__, |
| 13765 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13766 | AUTH_ASYNC, |
| 13767 | OK, |
| 13768 | kServer, |
| 13769 | AUTH_ASYNC, |
| 13770 | OK, |
| 13771 | 3, |
| 13772 | kNoSSL, |
| 13773 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13774 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13775 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13776 | {__LINE__, |
| 13777 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13778 | AUTH_ASYNC, |
| 13779 | OK, |
| 13780 | kServer, |
| 13781 | AUTH_ASYNC, |
| 13782 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13783 | 3, |
| 13784 | kNoSSL, |
| 13785 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13786 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13787 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13788 | {__LINE__, |
| 13789 | kProxy, |
| 13790 | AUTH_ASYNC, |
| 13791 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13792 | kServer, |
| 13793 | AUTH_ASYNC, |
| 13794 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13795 | 4, |
| 13796 | kNoSSL, |
| 13797 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13798 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13799 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13800 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13801 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13802 | {__LINE__, |
| 13803 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13804 | AUTH_NONE, |
| 13805 | OK, |
| 13806 | kSecureServer, |
| 13807 | AUTH_NONE, |
| 13808 | OK, |
| 13809 | 1, |
| 13810 | 0, |
| 13811 | {TestRound(kGet, kSuccess, OK)}}, |
| 13812 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13813 | {__LINE__, |
| 13814 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13815 | AUTH_NONE, |
| 13816 | OK, |
| 13817 | kSecureServer, |
| 13818 | AUTH_SYNC, |
| 13819 | OK, |
| 13820 | 2, |
| 13821 | 0, |
| 13822 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13823 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13824 | {__LINE__, |
| 13825 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13826 | AUTH_NONE, |
| 13827 | OK, |
| 13828 | kSecureServer, |
| 13829 | AUTH_SYNC, |
| 13830 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13831 | 2, |
| 13832 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13833 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13834 | {__LINE__, |
| 13835 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13836 | AUTH_NONE, |
| 13837 | OK, |
| 13838 | kSecureServer, |
| 13839 | AUTH_ASYNC, |
| 13840 | OK, |
| 13841 | 2, |
| 13842 | 0, |
| 13843 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13844 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13845 | {__LINE__, |
| 13846 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13847 | AUTH_NONE, |
| 13848 | OK, |
| 13849 | kSecureServer, |
| 13850 | AUTH_ASYNC, |
| 13851 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13852 | 2, |
| 13853 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13854 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13855 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13856 | {__LINE__, |
| 13857 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13858 | AUTH_NONE, |
| 13859 | OK, |
| 13860 | kSecureServer, |
| 13861 | AUTH_NONE, |
| 13862 | OK, |
| 13863 | 1, |
| 13864 | 0, |
| 13865 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13866 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13867 | {__LINE__, |
| 13868 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13869 | AUTH_NONE, |
| 13870 | OK, |
| 13871 | kSecureServer, |
| 13872 | AUTH_SYNC, |
| 13873 | OK, |
| 13874 | 2, |
| 13875 | 0, |
| 13876 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13877 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13878 | {__LINE__, |
| 13879 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13880 | AUTH_NONE, |
| 13881 | OK, |
| 13882 | kSecureServer, |
| 13883 | AUTH_SYNC, |
| 13884 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13885 | 2, |
| 13886 | 0, |
| 13887 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13888 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13889 | {__LINE__, |
| 13890 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13891 | AUTH_NONE, |
| 13892 | OK, |
| 13893 | kSecureServer, |
| 13894 | AUTH_ASYNC, |
| 13895 | OK, |
| 13896 | 2, |
| 13897 | 0, |
| 13898 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13899 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13900 | {__LINE__, |
| 13901 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13902 | AUTH_NONE, |
| 13903 | OK, |
| 13904 | kSecureServer, |
| 13905 | AUTH_ASYNC, |
| 13906 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13907 | 2, |
| 13908 | 0, |
| 13909 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13910 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13911 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13912 | {__LINE__, |
| 13913 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13914 | AUTH_SYNC, |
| 13915 | OK, |
| 13916 | kSecureServer, |
| 13917 | AUTH_NONE, |
| 13918 | OK, |
| 13919 | 2, |
| 13920 | 1, |
| 13921 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13922 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13923 | {__LINE__, |
| 13924 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13925 | AUTH_SYNC, |
| 13926 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13927 | kSecureServer, |
| 13928 | AUTH_NONE, |
| 13929 | OK, |
| 13930 | 2, |
| 13931 | kNoSSL, |
| 13932 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13933 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13934 | {__LINE__, |
| 13935 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13936 | AUTH_SYNC, |
| 13937 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13938 | kSecureServer, |
| 13939 | AUTH_NONE, |
| 13940 | OK, |
| 13941 | 2, |
| 13942 | kNoSSL, |
| 13943 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13944 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13945 | {__LINE__, |
| 13946 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13947 | AUTH_SYNC, |
| 13948 | ERR_UNEXPECTED, |
| 13949 | kSecureServer, |
| 13950 | AUTH_NONE, |
| 13951 | OK, |
| 13952 | 2, |
| 13953 | kNoSSL, |
| 13954 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13955 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13956 | {__LINE__, |
| 13957 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13958 | AUTH_ASYNC, |
| 13959 | OK, |
| 13960 | kSecureServer, |
| 13961 | AUTH_NONE, |
| 13962 | OK, |
| 13963 | 2, |
| 13964 | 1, |
| 13965 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13966 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
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 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13971 | kSecureServer, |
| 13972 | AUTH_NONE, |
| 13973 | OK, |
| 13974 | 2, |
| 13975 | kNoSSL, |
| 13976 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13977 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13978 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13979 | {__LINE__, |
| 13980 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13981 | AUTH_SYNC, |
| 13982 | OK, |
| 13983 | kSecureServer, |
| 13984 | AUTH_SYNC, |
| 13985 | OK, |
| 13986 | 3, |
| 13987 | 1, |
| 13988 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13989 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13990 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13991 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13992 | {__LINE__, |
| 13993 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13994 | AUTH_SYNC, |
| 13995 | OK, |
| 13996 | kSecureServer, |
| 13997 | AUTH_SYNC, |
| 13998 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13999 | 3, |
| 14000 | 1, |
| 14001 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14002 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14003 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14004 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14005 | {__LINE__, |
| 14006 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14007 | AUTH_ASYNC, |
| 14008 | OK, |
| 14009 | kSecureServer, |
| 14010 | AUTH_SYNC, |
| 14011 | OK, |
| 14012 | 3, |
| 14013 | 1, |
| 14014 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14015 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14016 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14017 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14018 | {__LINE__, |
| 14019 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14020 | AUTH_ASYNC, |
| 14021 | OK, |
| 14022 | kSecureServer, |
| 14023 | AUTH_SYNC, |
| 14024 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14025 | 3, |
| 14026 | 1, |
| 14027 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14028 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14029 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14030 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14031 | {__LINE__, |
| 14032 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14033 | AUTH_SYNC, |
| 14034 | OK, |
| 14035 | kSecureServer, |
| 14036 | AUTH_ASYNC, |
| 14037 | OK, |
| 14038 | 3, |
| 14039 | 1, |
| 14040 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14041 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14042 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14043 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14044 | {__LINE__, |
| 14045 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14046 | AUTH_SYNC, |
| 14047 | OK, |
| 14048 | kSecureServer, |
| 14049 | AUTH_ASYNC, |
| 14050 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14051 | 3, |
| 14052 | 1, |
| 14053 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14054 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14055 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14056 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14057 | {__LINE__, |
| 14058 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14059 | AUTH_ASYNC, |
| 14060 | OK, |
| 14061 | kSecureServer, |
| 14062 | AUTH_ASYNC, |
| 14063 | OK, |
| 14064 | 3, |
| 14065 | 1, |
| 14066 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14067 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14068 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14069 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14070 | {__LINE__, |
| 14071 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14072 | AUTH_ASYNC, |
| 14073 | OK, |
| 14074 | kSecureServer, |
| 14075 | AUTH_ASYNC, |
| 14076 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14077 | 3, |
| 14078 | 1, |
| 14079 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14080 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14081 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14082 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14083 | {__LINE__, |
| 14084 | kProxy, |
| 14085 | AUTH_ASYNC, |
| 14086 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14087 | kSecureServer, |
| 14088 | AUTH_ASYNC, |
| 14089 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14090 | 4, |
| 14091 | 2, |
| 14092 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14093 | TestRound(kConnect, kProxyChallenge, OK), |
| 14094 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14095 | &kServerChallenge), |
| 14096 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14097 | }; |
| 14098 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14099 | for (const auto& test_config : test_configs) { |
| 14100 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14101 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14102 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14103 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14104 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14105 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14106 | |
| 14107 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14108 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14109 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14110 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14111 | std::string auth_challenge = "Mock realm=proxy"; |
| 14112 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14113 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14114 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14115 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14116 | empty_ssl_info, origin, |
| 14117 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14118 | auth_handler->SetGenerateExpectation( |
| 14119 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14120 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14121 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14122 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14123 | } |
| 14124 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14125 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14126 | std::string auth_challenge = "Mock realm=server"; |
| 14127 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14128 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14129 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14130 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14131 | empty_ssl_info, origin, |
| 14132 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14133 | auth_handler->SetGenerateExpectation( |
| 14134 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14135 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14136 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14137 | |
| 14138 | // The second handler always succeeds. It should only be used where there |
| 14139 | // are multiple auth sessions for server auth in the same network |
| 14140 | // transaction using the same auth scheme. |
| 14141 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14142 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14143 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14144 | empty_ssl_info, origin, |
| 14145 | NetLogWithSource()); |
| 14146 | second_handler->SetGenerateExpectation(true, OK); |
| 14147 | auth_factory->AddMockHandler(second_handler.release(), |
| 14148 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14149 | } |
| 14150 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14151 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14152 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14153 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14154 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14155 | session_deps_.proxy_resolution_service = |
| 14156 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14157 | } |
| 14158 | |
| 14159 | HttpRequestInfo request; |
| 14160 | request.method = "GET"; |
| 14161 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14162 | request.traffic_annotation = |
| 14163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14164 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14165 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14166 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14167 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14168 | |
| 14169 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14170 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14171 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14172 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14173 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14174 | |
| 14175 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14176 | mock_reads.back().push_back(read_write_round.read); |
| 14177 | mock_writes.back().push_back(read_write_round.write); |
| 14178 | |
| 14179 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14180 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14181 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14182 | mock_reads.push_back(std::vector<MockRead>()); |
| 14183 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14184 | } |
| 14185 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14186 | if (read_write_round.extra_read) { |
| 14187 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14188 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14189 | if (read_write_round.extra_write) { |
| 14190 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14191 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14192 | |
| 14193 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14194 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14195 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14196 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14197 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14198 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14199 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14200 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14201 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14202 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14203 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14204 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14205 | } |
| 14206 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14207 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14208 | // they are as well. |
| 14209 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14210 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14211 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14212 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14213 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14214 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14215 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14216 | int rv; |
| 14217 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14218 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14219 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14220 | rv = trans.RestartWithAuth( |
| 14221 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14222 | } |
| 14223 | if (rv == ERR_IO_PENDING) |
| 14224 | rv = callback.WaitForResult(); |
| 14225 | |
| 14226 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14227 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14228 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14229 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14230 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14231 | continue; |
| 14232 | } |
| 14233 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14234 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14235 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14236 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14237 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14238 | } |
| 14239 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14240 | } |
| 14241 | } |
| 14242 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14243 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14244 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14245 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14246 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14247 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14248 | session_deps_.proxy_resolution_service = |
| 14249 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14250 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14251 | |
| 14252 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14253 | auth_handler->set_connection_based(true); |
| 14254 | std::string auth_challenge = "Mock realm=server"; |
| 14255 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14256 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14257 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14258 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14259 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14260 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14261 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14262 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14263 | int rv = OK; |
| 14264 | const HttpResponseInfo* response = NULL; |
| 14265 | HttpRequestInfo request; |
| 14266 | request.method = "GET"; |
| 14267 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14268 | request.traffic_annotation = |
| 14269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14270 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14272 | |
| 14273 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14274 | // to validate that the TCP socket is not released to the pool between |
| 14275 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14276 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14277 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14278 | 50, // Max sockets for pool |
| 14279 | 1, // Max sockets per group |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14280 | session_deps_.socket_factory.get(), session_deps_.host_resolver.get(), |
Matt Menke | 1751ba7 | 2019-02-09 02:23:46 | [diff] [blame] | 14281 | nullptr /* proxy_delegate */, session_deps_.cert_verifier.get(), |
| 14282 | session_deps_.channel_id_service.get(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14283 | session_deps_.transport_security_state.get(), |
| 14284 | session_deps_.cert_transparency_verifier.get(), |
| 14285 | session_deps_.ct_policy_enforcer.get(), |
Matt Menke | c94d97b | 2019-02-01 19:28:28 | [diff] [blame] | 14286 | nullptr /* ssl_client_session_cache */, |
Daniel McArdle | da3fa94 | 2019-02-15 16:41:21 | [diff] [blame^] | 14287 | nullptr /* ssl_client_session_cache_privacy_mode */, |
Matt Menke | fa9574f | 2019-01-28 18:55:27 | [diff] [blame] | 14288 | session_deps_.ssl_config_service.get(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14289 | nullptr /* socket_performance_watcher_factory */, |
| 14290 | nullptr /* network_quality_estimator */, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14291 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 14292 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14293 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14296 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14297 | |
| 14298 | const MockWrite kGet( |
| 14299 | "GET / HTTP/1.1\r\n" |
| 14300 | "Host: www.example.com\r\n" |
| 14301 | "Connection: keep-alive\r\n\r\n"); |
| 14302 | const MockWrite kGetAuth( |
| 14303 | "GET / HTTP/1.1\r\n" |
| 14304 | "Host: www.example.com\r\n" |
| 14305 | "Connection: keep-alive\r\n" |
| 14306 | "Authorization: auth_token\r\n\r\n"); |
| 14307 | |
| 14308 | const MockRead kServerChallenge( |
| 14309 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14310 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14311 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14312 | "Content-Length: 14\r\n\r\n" |
| 14313 | "Unauthorized\r\n"); |
| 14314 | const MockRead kSuccess( |
| 14315 | "HTTP/1.1 200 OK\r\n" |
| 14316 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14317 | "Content-Length: 3\r\n\r\n" |
| 14318 | "Yes"); |
| 14319 | |
| 14320 | MockWrite writes[] = { |
| 14321 | // First round |
| 14322 | kGet, |
| 14323 | // Second round |
| 14324 | kGetAuth, |
| 14325 | // Third round |
| 14326 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14327 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14328 | kGetAuth, |
| 14329 | // Competing request |
| 14330 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14331 | }; |
| 14332 | MockRead reads[] = { |
| 14333 | // First round |
| 14334 | kServerChallenge, |
| 14335 | // Second round |
| 14336 | kServerChallenge, |
| 14337 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14338 | kServerChallenge, |
| 14339 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14340 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14341 | // Competing response |
| 14342 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14343 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14344 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14345 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14346 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14347 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14348 | |
| 14349 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14350 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14351 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14352 | if (rv == ERR_IO_PENDING) |
| 14353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14354 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14355 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14356 | ASSERT_TRUE(response); |
| 14357 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14358 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14359 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14360 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14361 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14362 | // In between rounds, another request comes in for the same domain. |
| 14363 | // It should not be able to grab the TCP socket that trans has already |
| 14364 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14365 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14366 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14367 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14368 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14370 | // callback_compete.WaitForResult at this point would stall forever, |
| 14371 | // since the HttpNetworkTransaction does not release the request back to |
| 14372 | // the pool until after authentication completes. |
| 14373 | |
| 14374 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14375 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14376 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14377 | if (rv == ERR_IO_PENDING) |
| 14378 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14379 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14380 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14381 | ASSERT_TRUE(response); |
| 14382 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14383 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14384 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14385 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14386 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14387 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14388 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14389 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14390 | if (rv == ERR_IO_PENDING) |
| 14391 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14392 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14393 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14394 | ASSERT_TRUE(response); |
| 14395 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14396 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14397 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14398 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14399 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14400 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14401 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14402 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14403 | if (rv == ERR_IO_PENDING) |
| 14404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14405 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14406 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14407 | ASSERT_TRUE(response); |
| 14408 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14409 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14410 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14411 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14412 | // auth handler should transition to a DONE state in concert with the remote |
| 14413 | // server. But that's not something we can test here with a mock handler. |
| 14414 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14415 | auth_handler->state()); |
| 14416 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14417 | // Read the body since the fourth round was successful. This will also |
| 14418 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14419 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14420 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14421 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14422 | if (rv == ERR_IO_PENDING) |
| 14423 | rv = callback.WaitForResult(); |
| 14424 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14425 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14426 | EXPECT_EQ(0, rv); |
| 14427 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14428 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14429 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14430 | |
| 14431 | // The competing request can now finish. Wait for the headers and then |
| 14432 | // read the body. |
| 14433 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14434 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14435 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14436 | if (rv == ERR_IO_PENDING) |
| 14437 | rv = callback.WaitForResult(); |
| 14438 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14439 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14440 | EXPECT_EQ(0, rv); |
| 14441 | |
| 14442 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14443 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14444 | } |
| 14445 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14446 | // This tests the case that a request is issued via http instead of spdy after |
| 14447 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14448 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14449 | HttpRequestInfo request; |
| 14450 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14451 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14452 | request.traffic_annotation = |
| 14453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14454 | |
| 14455 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14456 | MockWrite( |
| 14457 | "GET / HTTP/1.1\r\n" |
| 14458 | "Host: www.example.org\r\n" |
| 14459 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14460 | }; |
| 14461 | |
| 14462 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14463 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14464 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14465 | MockRead("\r\n"), |
| 14466 | MockRead("hello world"), |
| 14467 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14468 | }; |
| 14469 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14470 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14471 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14472 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14474 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14475 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14476 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14478 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14479 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14482 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14483 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14484 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14486 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14488 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14489 | ASSERT_TRUE(response); |
| 14490 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14491 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14492 | |
| 14493 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14494 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14495 | EXPECT_EQ("hello world", response_data); |
| 14496 | |
| 14497 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14498 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14499 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14500 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14501 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14502 | // immediate server closing of the socket. |
| 14503 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14504 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14505 | HttpRequestInfo request; |
| 14506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14507 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14508 | request.traffic_annotation = |
| 14509 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14510 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14511 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14512 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14514 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14515 | spdy::SpdySerializedFrame req( |
| 14516 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14517 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14518 | |
| 14519 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14520 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14521 | }; |
| 14522 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14523 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14524 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14526 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14527 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14528 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14529 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14530 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14531 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14533 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14534 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14535 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14536 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14537 | // it gets it. This is needed since the auth handler may get destroyed |
| 14538 | // before we get a chance to query it. |
| 14539 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14540 | public: |
| 14541 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14542 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14543 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14544 | |
| 14545 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14546 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14547 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14548 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14549 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14550 | *url_ = request->url; |
| 14551 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14552 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14553 | } |
| 14554 | |
| 14555 | private: |
| 14556 | GURL* url_; |
| 14557 | }; |
| 14558 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14559 | // Test that if we cancel the transaction as the connection is completing, that |
| 14560 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14561 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14562 | // Setup everything about the connection to complete synchronously, so that |
| 14563 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14564 | // for is the callback from the HttpStreamRequest. |
| 14565 | // Then cancel the transaction. |
| 14566 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14567 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14568 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14569 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14570 | MockRead(SYNCHRONOUS, "hello world"), |
| 14571 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14572 | }; |
| 14573 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 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 | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14577 | request.traffic_annotation = |
| 14578 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14579 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14581 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14582 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14583 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14584 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14585 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14588 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14589 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14590 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14591 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14593 | trans.reset(); // Cancel the transaction here. |
| 14594 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14595 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14596 | } |
| 14597 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14598 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14599 | // stream is drained properly and added back to the socket pool. The main |
| 14600 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14601 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14602 | // deleted. |
| 14603 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14604 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14605 | MockRead data_reads[] = { |
| 14606 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14607 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14608 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14609 | MockRead(ASYNC, "1"), |
| 14610 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14611 | // HttpNetworkTransaction has been deleted. |
| 14612 | MockRead(ASYNC, "2"), |
| 14613 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14614 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14615 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14617 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14618 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14619 | |
| 14620 | { |
| 14621 | HttpRequestInfo request; |
| 14622 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14623 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14624 | request.traffic_annotation = |
| 14625 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14626 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14628 | TestCompletionCallback callback; |
| 14629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14632 | callback.WaitForResult(); |
| 14633 | |
| 14634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14635 | ASSERT_TRUE(response); |
| 14636 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14637 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14638 | |
| 14639 | // The transaction and HttpRequestInfo are deleted. |
| 14640 | } |
| 14641 | |
| 14642 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14643 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14644 | |
| 14645 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14646 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14647 | } |
| 14648 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14649 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14650 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14651 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14652 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14653 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14654 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14655 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14657 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14658 | HttpRequestInfo request; |
| 14659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14660 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14661 | request.traffic_annotation = |
| 14662 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14663 | |
| 14664 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14665 | MockWrite( |
| 14666 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14667 | "Host: www.example.org\r\n" |
| 14668 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14669 | }; |
| 14670 | |
| 14671 | MockRead data_reads1[] = { |
| 14672 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14673 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14674 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14675 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14676 | }; |
| 14677 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14678 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14679 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14681 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14684 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14685 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14686 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14687 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14689 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14691 | |
| 14692 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14693 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14695 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14696 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14697 | |
| 14698 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14699 | EXPECT_EQ(200, response->headers->response_code()); |
| 14700 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14701 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14702 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14703 | HostPortPair::FromString("myproxy:70")), |
| 14704 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14705 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14706 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14707 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14708 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14709 | |
| 14710 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14711 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14712 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14713 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14714 | } |
| 14715 | |
| 14716 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14717 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14718 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14719 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14720 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14721 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14722 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14724 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14725 | HttpRequestInfo request; |
| 14726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14727 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14728 | request.traffic_annotation = |
| 14729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14730 | |
| 14731 | // Since we have proxy, should try to establish tunnel. |
| 14732 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14733 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14734 | "Host: www.example.org:443\r\n" |
| 14735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14736 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14737 | MockWrite("GET / HTTP/1.1\r\n" |
| 14738 | "Host: www.example.org\r\n" |
| 14739 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14740 | }; |
| 14741 | |
| 14742 | MockRead data_reads1[] = { |
| 14743 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14744 | |
| 14745 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14746 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14747 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14748 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14749 | }; |
| 14750 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14751 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14753 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14756 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14759 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14760 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14761 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14762 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14764 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14765 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14766 | |
| 14767 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14768 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14769 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14770 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14771 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14772 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14773 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14774 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14775 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14776 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14777 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14779 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14780 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14781 | |
| 14782 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14783 | EXPECT_EQ(200, response->headers->response_code()); |
| 14784 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14785 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14786 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14787 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14788 | HostPortPair::FromString("myproxy:70")), |
| 14789 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14790 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14791 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14792 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14793 | |
| 14794 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14795 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14796 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14797 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14798 | } |
| 14799 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14800 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14801 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14802 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14803 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14804 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14805 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14806 | BoundTestNetLog log; |
| 14807 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14809 | |
| 14810 | HttpRequestInfo request; |
| 14811 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14812 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14813 | request.traffic_annotation = |
| 14814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14815 | |
| 14816 | // Since we have proxy, should try to establish tunnel. |
| 14817 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14818 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14819 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14820 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14821 | |
| 14822 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14823 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14824 | "Connection: keep-alive\r\n\r\n"), |
| 14825 | }; |
| 14826 | |
| 14827 | MockRead data_reads1[] = { |
| 14828 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14829 | |
| 14830 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14831 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14832 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14833 | MockRead(SYNCHRONOUS, OK), |
| 14834 | }; |
| 14835 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14836 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14837 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14838 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14839 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14840 | |
| 14841 | TestCompletionCallback callback1; |
| 14842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14843 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14845 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14847 | |
| 14848 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14849 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14850 | TestNetLogEntry::List entries; |
| 14851 | log.GetEntries(&entries); |
| 14852 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14853 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14854 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14855 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14856 | entries, pos, |
| 14857 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14858 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14860 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14861 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14862 | |
| 14863 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14864 | EXPECT_EQ(200, response->headers->response_code()); |
| 14865 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14866 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14867 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14868 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14869 | HostPortPair::FromString("myproxy:70")), |
| 14870 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14871 | |
| 14872 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14873 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14874 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14875 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14876 | } |
| 14877 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14878 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14879 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14880 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14881 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14882 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14883 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14884 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14886 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14887 | HttpRequestInfo request; |
| 14888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14889 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14890 | request.traffic_annotation = |
| 14891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14892 | |
| 14893 | // Since we have proxy, should try to establish tunnel. |
| 14894 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14895 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14896 | "Host: www.example.org:443\r\n" |
| 14897 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14898 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14899 | MockWrite("GET / HTTP/1.1\r\n" |
| 14900 | "Host: www.example.org\r\n" |
| 14901 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14902 | }; |
| 14903 | |
| 14904 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14905 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14906 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14907 | }; |
| 14908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14909 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14910 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14911 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14914 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14918 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14920 | |
| 14921 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14922 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14923 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14924 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14925 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14926 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14927 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14928 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14929 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14930 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14931 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14932 | } |
| 14933 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14934 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14935 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14936 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14937 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14938 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14939 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14940 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14941 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14942 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14943 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14944 | }; |
| 14945 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14946 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14947 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14948 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14949 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14950 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14952 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14953 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14954 | |
| 14955 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14956 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14957 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 14958 | PRIVACY_MODE_DISABLED, |
| 14959 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14960 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14961 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14962 | |
| 14963 | HttpRequestInfo request; |
| 14964 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14965 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14966 | request.traffic_annotation = |
| 14967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14970 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14971 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14972 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14974 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14975 | } |
| 14976 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14977 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14978 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14979 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14980 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14981 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14982 | request_info.url = GURL("https://www.example.com/"); |
| 14983 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14984 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14985 | request_info.traffic_annotation = |
| 14986 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14987 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14988 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14989 | MockWrite data_writes[] = { |
| 14990 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14991 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14992 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14993 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14995 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14997 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14999 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15000 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15001 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15002 | rv = callback.WaitForResult(); |
| 15003 | ASSERT_EQ(error, rv); |
| 15004 | } |
| 15005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15006 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15007 | // Just check a grab bag of cert errors. |
| 15008 | static const int kErrors[] = { |
| 15009 | ERR_CERT_COMMON_NAME_INVALID, |
| 15010 | ERR_CERT_AUTHORITY_INVALID, |
| 15011 | ERR_CERT_DATE_INVALID, |
| 15012 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15013 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15014 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15015 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15016 | } |
| 15017 | } |
| 15018 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15019 | // Ensure that a client certificate is removed from the SSL client auth |
| 15020 | // cache when: |
| 15021 | // 1) No proxy is involved. |
| 15022 | // 2) TLS False Start is disabled. |
| 15023 | // 3) The initial TLS handshake requests a client certificate. |
| 15024 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15025 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15026 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15027 | request_info.url = GURL("https://www.example.com/"); |
| 15028 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15029 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15030 | request_info.traffic_annotation = |
| 15031 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15032 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15033 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15034 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15035 | |
| 15036 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15037 | // CertificateRequest is received for the first time, the handshake will |
| 15038 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15039 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15040 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15041 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15042 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15043 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15044 | |
| 15045 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15046 | // False Start is not being used, the result of the SSL handshake will be |
| 15047 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15048 | // matches the result of a server sending a handshake_failure alert, |
| 15049 | // rather than a Finished message, because it requires a client |
| 15050 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15051 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15052 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15054 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15055 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15056 | |
| 15057 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15058 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15059 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15060 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15061 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15062 | // requiring a client certificate, this fallback handshake should also |
| 15063 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15064 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15065 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15066 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15068 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15069 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15070 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15071 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15072 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15073 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15074 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15075 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15076 | // requiring a client certificate, this fallback handshake should also |
| 15077 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15078 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15079 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15081 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15082 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15086 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15087 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15088 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15089 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15090 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15091 | |
| 15092 | // Complete the SSL handshake, which should abort due to requiring a |
| 15093 | // client certificate. |
| 15094 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15095 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15096 | |
| 15097 | // Indicate that no certificate should be supplied. From the perspective |
| 15098 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15099 | // certificate, so this is the same as supply a |
| 15100 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15101 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15102 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15103 | |
| 15104 | // Ensure the certificate was added to the client auth cache before |
| 15105 | // allowing the connection to continue restarting. |
| 15106 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15107 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15108 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15109 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15110 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15111 | |
| 15112 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15113 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15114 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15115 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15116 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15117 | |
| 15118 | // Ensure that the client certificate is removed from the cache on a |
| 15119 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15120 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15121 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15122 | } |
| 15123 | |
| 15124 | // Ensure that a client certificate is removed from the SSL client auth |
| 15125 | // cache when: |
| 15126 | // 1) No proxy is involved. |
| 15127 | // 2) TLS False Start is enabled. |
| 15128 | // 3) The initial TLS handshake requests a client certificate. |
| 15129 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15130 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15131 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15132 | request_info.url = GURL("https://www.example.com/"); |
| 15133 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15134 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15135 | request_info.traffic_annotation = |
| 15136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15137 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15138 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15139 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15140 | |
| 15141 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15142 | // return successfully after reading up to the peer's Certificate message. |
| 15143 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15144 | // enqueue application data to be sent in the same packet as the |
| 15145 | // ChangeCipherSpec and Finished messages. |
| 15146 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15147 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15148 | // Finished messages. If there was an error negotiating with the peer, |
| 15149 | // such as due to the peer requiring a client certificate when none was |
| 15150 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15151 | // called. |
| 15152 | |
| 15153 | // Like the non-False Start case, when a client certificate is requested by |
| 15154 | // the peer, the handshake is aborted during the Connect() call. |
| 15155 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15156 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15157 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15158 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15159 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15160 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15161 | |
| 15162 | // When a client certificate is supplied, Connect() will not be aborted |
| 15163 | // when the peer requests the certificate. Instead, the handshake will |
| 15164 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15165 | // the socket. The handshake messages are not processed until Read() is |
| 15166 | // called, which then detects that the handshake was aborted, due to the |
| 15167 | // peer sending a handshake_failure because it requires a client |
| 15168 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15169 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15170 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15172 | MockRead data2_reads[] = { |
| 15173 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15174 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15175 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15176 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15177 | |
| 15178 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15179 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15180 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15181 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15182 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15184 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15185 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15186 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15187 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15188 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15189 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15190 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15191 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15192 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15193 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15194 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15195 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15196 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15197 | ssl_data5.cert_request_info = cert_request.get(); |
| 15198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15199 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15200 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15201 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15203 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15204 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15205 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15206 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15207 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15208 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15209 | |
| 15210 | // Complete the SSL handshake, which should abort due to requiring a |
| 15211 | // client certificate. |
| 15212 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15213 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15214 | |
| 15215 | // Indicate that no certificate should be supplied. From the perspective |
| 15216 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15217 | // certificate, so this is the same as supply a |
| 15218 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15219 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15220 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15221 | |
| 15222 | // Ensure the certificate was added to the client auth cache before |
| 15223 | // allowing the connection to continue restarting. |
| 15224 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15225 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15226 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15227 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15228 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15229 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15230 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15231 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15232 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15233 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15234 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15235 | |
| 15236 | // Ensure that the client certificate is removed from the cache on a |
| 15237 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15238 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15239 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15240 | } |
| 15241 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15242 | // Ensure that a client certificate is removed from the SSL client auth |
| 15243 | // cache when: |
| 15244 | // 1) An HTTPS proxy is involved. |
| 15245 | // 3) The HTTPS proxy requests a client certificate. |
| 15246 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15247 | // proxy. |
| 15248 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15249 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15250 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15251 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15252 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15253 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15254 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15255 | |
| 15256 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15257 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15258 | |
| 15259 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15260 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15261 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15262 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15263 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15264 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15266 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15267 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15268 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15269 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15270 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15272 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15273 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15274 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15275 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15276 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15277 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15278 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15279 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15280 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15281 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15282 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15283 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15284 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15285 | requests[0].url = GURL("https://www.example.com/"); |
| 15286 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15287 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15288 | requests[0].traffic_annotation = |
| 15289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15290 | |
| 15291 | requests[1].url = GURL("http://www.example.com/"); |
| 15292 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15293 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15294 | requests[1].traffic_annotation = |
| 15295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15296 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15297 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15298 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15301 | |
| 15302 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15303 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15304 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15305 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15306 | |
| 15307 | // Complete the SSL handshake, which should abort due to requiring a |
| 15308 | // client certificate. |
| 15309 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15310 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15311 | |
| 15312 | // Indicate that no certificate should be supplied. From the perspective |
| 15313 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15314 | // certificate, so this is the same as supply a |
| 15315 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15316 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15317 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15318 | |
| 15319 | // Ensure the certificate was added to the client auth cache before |
| 15320 | // allowing the connection to continue restarting. |
| 15321 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15322 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15323 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15324 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15325 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15326 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15327 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15328 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15329 | HostPortPair("www.example.com", 443), &client_cert, |
| 15330 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15331 | |
| 15332 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15333 | // then consume ssl_data3, which should also fail. The result code is |
| 15334 | // checked against what ssl_data3 should return. |
| 15335 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15336 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15337 | |
| 15338 | // Now that the new handshake has failed, ensure that the client |
| 15339 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15340 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15341 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15342 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15343 | HostPortPair("www.example.com", 443), &client_cert, |
| 15344 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15345 | } |
| 15346 | } |
| 15347 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15348 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15349 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15350 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15351 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15352 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15353 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15354 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15355 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15356 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15357 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15358 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15359 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15360 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15361 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15362 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15363 | spdy::SpdySerializedFrame host1_resp( |
| 15364 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15365 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15366 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15367 | spdy::SpdySerializedFrame host2_resp( |
| 15368 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15369 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15370 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15371 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15372 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15373 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15374 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15375 | }; |
| 15376 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15377 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15378 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15379 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15380 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15381 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15382 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15383 | HttpRequestInfo request1; |
| 15384 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15385 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15386 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15387 | request1.traffic_annotation = |
| 15388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15389 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15390 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15391 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15393 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15394 | |
| 15395 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15396 | ASSERT_TRUE(response); |
| 15397 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15398 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15399 | |
| 15400 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15401 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15402 | EXPECT_EQ("hello!", response_data); |
| 15403 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15404 | // Preload mail.example.com into HostCache. |
| 15405 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 15406 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15407 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15408 | std::unique_ptr<HostResolver::Request> request; |
| 15409 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15410 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15411 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15413 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15414 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15415 | |
| 15416 | HttpRequestInfo request2; |
| 15417 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15418 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15419 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15420 | request2.traffic_annotation = |
| 15421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15422 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15423 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15424 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15426 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15427 | |
| 15428 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15429 | ASSERT_TRUE(response); |
| 15430 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15431 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15432 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15433 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15434 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15435 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15436 | } |
| 15437 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15438 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15439 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15440 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15442 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15443 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15444 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15445 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15446 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15447 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15448 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15449 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15450 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15451 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15452 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15453 | spdy::SpdySerializedFrame host1_resp( |
| 15454 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15455 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15456 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15457 | spdy::SpdySerializedFrame host2_resp( |
| 15458 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15459 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15460 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15461 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15462 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15463 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15464 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15465 | }; |
| 15466 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15467 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15468 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15469 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15470 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15471 | |
| 15472 | TestCompletionCallback callback; |
| 15473 | HttpRequestInfo request1; |
| 15474 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15475 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15476 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15477 | request1.traffic_annotation = |
| 15478 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15479 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15480 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15481 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15483 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15484 | |
| 15485 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15486 | ASSERT_TRUE(response); |
| 15487 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15488 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15489 | |
| 15490 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15491 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15492 | EXPECT_EQ("hello!", response_data); |
| 15493 | |
| 15494 | HttpRequestInfo request2; |
| 15495 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15496 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15497 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15498 | request2.traffic_annotation = |
| 15499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15500 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15501 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15502 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15503 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15504 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15505 | |
| 15506 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15507 | ASSERT_TRUE(response); |
| 15508 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15509 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15510 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15511 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15512 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15513 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15514 | } |
| 15515 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15516 | // Regression test for https://crbug.com/546991. |
| 15517 | // The server might not be able to serve an IP pooled request, and might send a |
| 15518 | // 421 Misdirected Request response status to indicate this. |
| 15519 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15520 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15521 | // Two hosts resolve to the same IP address. |
| 15522 | const std::string ip_addr = "1.2.3.4"; |
| 15523 | IPAddress ip; |
| 15524 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15525 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15526 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15527 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15528 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15529 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15530 | |
| 15531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15532 | |
| 15533 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15534 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15535 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15536 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15537 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15538 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15539 | spdy::SpdySerializedFrame rst( |
| 15540 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15541 | MockWrite writes1[] = { |
| 15542 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15543 | CreateMockWrite(rst, 6), |
| 15544 | }; |
| 15545 | |
| 15546 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15547 | spdy::SpdySerializedFrame resp1( |
| 15548 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15549 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15550 | spdy::SpdyHeaderBlock response_headers; |
| 15551 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15552 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15553 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15554 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15555 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15556 | |
| 15557 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15558 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15560 | |
| 15561 | AddSSLSocketData(); |
| 15562 | |
| 15563 | // Retry the second request on a second connection. |
| 15564 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15565 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15566 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15567 | MockWrite writes2[] = { |
| 15568 | CreateMockWrite(req3, 0), |
| 15569 | }; |
| 15570 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15571 | spdy::SpdySerializedFrame resp3( |
| 15572 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15573 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15574 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15575 | MockRead(ASYNC, 0, 3)}; |
| 15576 | |
| 15577 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15578 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15579 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15580 | |
| 15581 | AddSSLSocketData(); |
| 15582 | |
| 15583 | // Preload mail.example.org into HostCache. |
| 15584 | HostPortPair host_port("mail.example.org", 443); |
| 15585 | HostResolver::RequestInfo resolve_info(host_port); |
| 15586 | AddressList ignored; |
| 15587 | std::unique_ptr<HostResolver::Request> request; |
| 15588 | TestCompletionCallback callback; |
| 15589 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15590 | &ignored, callback.callback(), |
| 15591 | &request, NetLogWithSource()); |
| 15592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15593 | rv = callback.WaitForResult(); |
| 15594 | EXPECT_THAT(rv, IsOk()); |
| 15595 | |
| 15596 | HttpRequestInfo request1; |
| 15597 | request1.method = "GET"; |
| 15598 | request1.url = GURL("https://www.example.org/"); |
| 15599 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15600 | request1.traffic_annotation = |
| 15601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15602 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15603 | |
| 15604 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15606 | rv = callback.WaitForResult(); |
| 15607 | EXPECT_THAT(rv, IsOk()); |
| 15608 | |
| 15609 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15610 | ASSERT_TRUE(response); |
| 15611 | ASSERT_TRUE(response->headers); |
| 15612 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15613 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15614 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15615 | std::string response_data; |
| 15616 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15617 | EXPECT_EQ("hello!", response_data); |
| 15618 | |
| 15619 | HttpRequestInfo request2; |
| 15620 | request2.method = "GET"; |
| 15621 | request2.url = GURL("https://mail.example.org/"); |
| 15622 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15623 | request2.traffic_annotation = |
| 15624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15625 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15626 | |
| 15627 | BoundTestNetLog log; |
| 15628 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15630 | rv = callback.WaitForResult(); |
| 15631 | EXPECT_THAT(rv, IsOk()); |
| 15632 | |
| 15633 | response = trans2.GetResponseInfo(); |
| 15634 | ASSERT_TRUE(response); |
| 15635 | ASSERT_TRUE(response->headers); |
| 15636 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15637 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15638 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15639 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15640 | EXPECT_EQ("hello!", response_data); |
| 15641 | |
| 15642 | TestNetLogEntry::List entries; |
| 15643 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15644 | ExpectLogContainsSomewhere( |
| 15645 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15646 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15647 | } |
| 15648 | |
| 15649 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15650 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15651 | // portions of the response. |
| 15652 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15653 | // Two hosts resolve to the same IP address. |
| 15654 | const std::string ip_addr = "1.2.3.4"; |
| 15655 | IPAddress ip; |
| 15656 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15657 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15658 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15659 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15660 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15661 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15662 | |
| 15663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15664 | |
| 15665 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15666 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15667 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15668 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15669 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15670 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15671 | spdy::SpdySerializedFrame rst( |
| 15672 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15673 | MockWrite writes1[] = { |
| 15674 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15675 | CreateMockWrite(rst, 6), |
| 15676 | }; |
| 15677 | |
| 15678 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15679 | spdy::SpdySerializedFrame resp1( |
| 15680 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15681 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15682 | spdy::SpdyHeaderBlock response_headers; |
| 15683 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15684 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15685 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15686 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15687 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15688 | |
| 15689 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15690 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15691 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15692 | |
| 15693 | AddSSLSocketData(); |
| 15694 | |
| 15695 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15696 | // Retry again. |
| 15697 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15698 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15699 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15700 | MockWrite writes2[] = { |
| 15701 | CreateMockWrite(req3, 0), |
| 15702 | }; |
| 15703 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15704 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15705 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15706 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15707 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15708 | MockRead(ASYNC, 0, 3)}; |
| 15709 | |
| 15710 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15711 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15712 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15713 | |
| 15714 | AddSSLSocketData(); |
| 15715 | |
| 15716 | // Preload mail.example.org into HostCache. |
| 15717 | HostPortPair host_port("mail.example.org", 443); |
| 15718 | HostResolver::RequestInfo resolve_info(host_port); |
| 15719 | AddressList ignored; |
| 15720 | std::unique_ptr<HostResolver::Request> request; |
| 15721 | TestCompletionCallback callback; |
| 15722 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15723 | &ignored, callback.callback(), |
| 15724 | &request, NetLogWithSource()); |
| 15725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15726 | rv = callback.WaitForResult(); |
| 15727 | EXPECT_THAT(rv, IsOk()); |
| 15728 | |
| 15729 | HttpRequestInfo request1; |
| 15730 | request1.method = "GET"; |
| 15731 | request1.url = GURL("https://www.example.org/"); |
| 15732 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15733 | request1.traffic_annotation = |
| 15734 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15735 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15736 | |
| 15737 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15739 | rv = callback.WaitForResult(); |
| 15740 | EXPECT_THAT(rv, IsOk()); |
| 15741 | |
| 15742 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15743 | ASSERT_TRUE(response); |
| 15744 | ASSERT_TRUE(response->headers); |
| 15745 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15746 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15747 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15748 | std::string response_data; |
| 15749 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15750 | EXPECT_EQ("hello!", response_data); |
| 15751 | |
| 15752 | HttpRequestInfo request2; |
| 15753 | request2.method = "GET"; |
| 15754 | request2.url = GURL("https://mail.example.org/"); |
| 15755 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15756 | request2.traffic_annotation = |
| 15757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15758 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15759 | |
| 15760 | BoundTestNetLog log; |
| 15761 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15763 | rv = callback.WaitForResult(); |
| 15764 | EXPECT_THAT(rv, IsOk()); |
| 15765 | |
| 15766 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15767 | // caller. |
| 15768 | response = trans2.GetResponseInfo(); |
| 15769 | ASSERT_TRUE(response); |
| 15770 | ASSERT_TRUE(response->headers); |
| 15771 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15772 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15773 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15774 | EXPECT_TRUE(response->ssl_info.cert); |
| 15775 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15776 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15777 | } |
| 15778 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15779 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15780 | public: |
| 15781 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15782 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15783 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15784 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15785 | int ResolveFromCache(const RequestInfo& info, |
| 15786 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15787 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15788 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 15789 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15790 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15791 | return rv; |
| 15792 | } |
| 15793 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15794 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15795 | const HostPortPair host_port_; |
| 15796 | }; |
| 15797 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15798 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15799 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15800 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15801 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15802 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15804 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15805 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15806 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15807 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15808 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15809 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15810 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15811 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15812 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15813 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15814 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15815 | spdy::SpdySerializedFrame host1_resp( |
| 15816 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15817 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15818 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15819 | spdy::SpdySerializedFrame host2_resp( |
| 15820 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15821 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15822 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15823 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15824 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15825 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15826 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15827 | }; |
| 15828 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15829 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15830 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15831 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15832 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15833 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15834 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15835 | HttpRequestInfo request1; |
| 15836 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15837 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15838 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15839 | request1.traffic_annotation = |
| 15840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15841 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15842 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15843 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15845 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15846 | |
| 15847 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15848 | ASSERT_TRUE(response); |
| 15849 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15850 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15851 | |
| 15852 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15853 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15854 | EXPECT_EQ("hello!", response_data); |
| 15855 | |
| 15856 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15857 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15858 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15859 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15860 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15861 | &ignored, callback.callback(), |
| 15862 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15864 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15865 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15866 | |
| 15867 | HttpRequestInfo request2; |
| 15868 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15869 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15870 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15871 | request2.traffic_annotation = |
| 15872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15873 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15874 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15875 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15877 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15878 | |
| 15879 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15880 | ASSERT_TRUE(response); |
| 15881 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15882 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15883 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15884 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15885 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15886 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15887 | } |
| 15888 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15889 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15890 | const std::string https_url = "https://www.example.org:8080/"; |
| 15891 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15892 | |
| 15893 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15894 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15895 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15896 | |
| 15897 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15898 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15899 | }; |
| 15900 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15901 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15902 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15903 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15904 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15905 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15906 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15907 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15908 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15909 | |
| 15910 | // HTTP GET for the HTTP URL |
| 15911 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15912 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15913 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15914 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15915 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15916 | }; |
| 15917 | |
| 15918 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15919 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15920 | MockRead(ASYNC, 2, "hello"), |
| 15921 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15922 | }; |
| 15923 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15924 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15925 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15926 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15927 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15928 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15929 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15930 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15931 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15933 | |
| 15934 | // Start the first transaction to set up the SpdySession |
| 15935 | HttpRequestInfo request1; |
| 15936 | request1.method = "GET"; |
| 15937 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15938 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15939 | request1.traffic_annotation = |
| 15940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15941 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15942 | TestCompletionCallback callback1; |
| 15943 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15944 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15945 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15946 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15947 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15948 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15949 | |
| 15950 | // Now, start the HTTP request |
| 15951 | HttpRequestInfo request2; |
| 15952 | request2.method = "GET"; |
| 15953 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15954 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15955 | request2.traffic_annotation = |
| 15956 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15957 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15958 | TestCompletionCallback callback2; |
| 15959 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15960 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15961 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15962 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15963 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15964 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15965 | } |
| 15966 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15967 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15968 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15969 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15970 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15971 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15972 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15973 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15974 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15975 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15976 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15977 | |
| 15978 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15979 | // negotiated. |
| 15980 | StaticSocketDataProvider data; |
| 15981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15982 | |
| 15983 | // 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] | 15984 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15985 | // mocked. This way the request relies on the alternate Job. |
| 15986 | StaticSocketDataProvider data_refused; |
| 15987 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15988 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15989 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15990 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15991 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15992 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15993 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15994 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15995 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15996 | http_server_properties->SetHttp2AlternativeService( |
| 15997 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15998 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15999 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16000 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16001 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16002 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16003 | request.traffic_annotation = |
| 16004 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16005 | TestCompletionCallback callback; |
| 16006 | |
| 16007 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16008 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16009 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16010 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16011 | } |
| 16012 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16013 | // 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] | 16014 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16015 | // succeeds, the request should succeed, even if the latter fails because |
| 16016 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16017 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16018 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16019 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16020 | |
| 16021 | // Negotiate HTTP/1.1 with alternative. |
| 16022 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16023 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16025 | |
| 16026 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16027 | // negotiated. |
| 16028 | StaticSocketDataProvider data; |
| 16029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16030 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16031 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16032 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16033 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16035 | |
| 16036 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16037 | MockWrite("GET / HTTP/1.1\r\n" |
| 16038 | "Host: www.example.org\r\n" |
| 16039 | "Connection: keep-alive\r\n\r\n"), |
| 16040 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16041 | "Host: www.example.org\r\n" |
| 16042 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16043 | }; |
| 16044 | |
| 16045 | MockRead http_reads[] = { |
| 16046 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16047 | MockRead("Content-Type: text/html\r\n"), |
| 16048 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16049 | MockRead("foobar"), |
| 16050 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16051 | MockRead("Content-Type: text/html\r\n"), |
| 16052 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16053 | MockRead("another"), |
| 16054 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16055 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16056 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16057 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16058 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16059 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16060 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16061 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16062 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16063 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16064 | http_server_properties->SetHttp2AlternativeService( |
| 16065 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16066 | |
| 16067 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16068 | HttpRequestInfo request1; |
| 16069 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16070 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16071 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16072 | request1.traffic_annotation = |
| 16073 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16074 | TestCompletionCallback callback1; |
| 16075 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16076 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16077 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16078 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16079 | |
| 16080 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16081 | ASSERT_TRUE(response1); |
| 16082 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16083 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16084 | |
| 16085 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16086 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16087 | EXPECT_EQ("foobar", response_data1); |
| 16088 | |
| 16089 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16090 | // for alternative service. |
| 16091 | EXPECT_TRUE( |
| 16092 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16093 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16094 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16095 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16096 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16097 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16098 | HttpRequestInfo request2; |
| 16099 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16100 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16101 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16102 | request2.traffic_annotation = |
| 16103 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16104 | TestCompletionCallback callback2; |
| 16105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16106 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16107 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16108 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16109 | |
| 16110 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16111 | ASSERT_TRUE(response2); |
| 16112 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16113 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16114 | |
| 16115 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16116 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16117 | EXPECT_EQ("another", response_data2); |
| 16118 | } |
| 16119 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16120 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16121 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16122 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16123 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16124 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16125 | HostPortPair alternative("alternative.example.org", 443); |
| 16126 | std::string origin_url = "https://origin.example.org:443"; |
| 16127 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16128 | |
| 16129 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16130 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16131 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16132 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16133 | |
| 16134 | // HTTP/1.1 data for |request1| and |request2|. |
| 16135 | MockWrite http_writes[] = { |
| 16136 | MockWrite( |
| 16137 | "GET / HTTP/1.1\r\n" |
| 16138 | "Host: alternative.example.org\r\n" |
| 16139 | "Connection: keep-alive\r\n\r\n"), |
| 16140 | MockWrite( |
| 16141 | "GET / HTTP/1.1\r\n" |
| 16142 | "Host: alternative.example.org\r\n" |
| 16143 | "Connection: keep-alive\r\n\r\n"), |
| 16144 | }; |
| 16145 | |
| 16146 | MockRead http_reads[] = { |
| 16147 | MockRead( |
| 16148 | "HTTP/1.1 200 OK\r\n" |
| 16149 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16150 | "Content-Length: 40\r\n\r\n" |
| 16151 | "first HTTP/1.1 response from alternative"), |
| 16152 | MockRead( |
| 16153 | "HTTP/1.1 200 OK\r\n" |
| 16154 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16155 | "Content-Length: 41\r\n\r\n" |
| 16156 | "second HTTP/1.1 response from alternative"), |
| 16157 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16158 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16159 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16160 | |
| 16161 | // This test documents that an alternate Job should not pool to an already |
| 16162 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16163 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16164 | StaticSocketDataProvider data_refused; |
| 16165 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16166 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16167 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16168 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16169 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16170 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16171 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16172 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16173 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16174 | http_server_properties->SetHttp2AlternativeService( |
| 16175 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16176 | |
| 16177 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16178 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16179 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16180 | request1.method = "GET"; |
| 16181 | request1.url = GURL(alternative_url); |
| 16182 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16183 | request1.traffic_annotation = |
| 16184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16185 | TestCompletionCallback callback1; |
| 16186 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16187 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16188 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16189 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16190 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16191 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16192 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16193 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16194 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16195 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16196 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16197 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16198 | |
| 16199 | // Request for origin.example.org, which has an alternative service. This |
| 16200 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16201 | // 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] | 16202 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16203 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16204 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16205 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16206 | request2.method = "GET"; |
| 16207 | request2.url = GURL(origin_url); |
| 16208 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16209 | request2.traffic_annotation = |
| 16210 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16211 | TestCompletionCallback callback2; |
| 16212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16213 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16214 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16215 | |
| 16216 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16217 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16218 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16219 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16220 | request3.method = "GET"; |
| 16221 | request3.url = GURL(alternative_url); |
| 16222 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16223 | request3.traffic_annotation = |
| 16224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16225 | TestCompletionCallback callback3; |
| 16226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16227 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16228 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16229 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16230 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16231 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16232 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16233 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16234 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16235 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16236 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16237 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16238 | } |
| 16239 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16240 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16241 | const std::string https_url = "https://www.example.org:8080/"; |
| 16242 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16243 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16244 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16245 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16246 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16247 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16248 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16249 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16250 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16251 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16252 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16253 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16254 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16255 | |
| 16256 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16257 | spdy::SpdyHeaderBlock req2_block; |
| 16258 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16259 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16260 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16261 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16262 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16263 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16264 | |
| 16265 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16266 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16267 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16268 | }; |
| 16269 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16270 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16271 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16272 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16273 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16274 | spdy::SpdySerializedFrame body1( |
| 16275 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16276 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16277 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16278 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16279 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16280 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 16281 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16282 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16283 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16284 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16285 | CreateMockRead(wrapped_resp1, 4), |
| 16286 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16287 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16288 | CreateMockRead(resp2, 8), |
| 16289 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16290 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16291 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16292 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16293 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16294 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16295 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16296 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16297 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16298 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16299 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16300 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16301 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16302 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16303 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16304 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16305 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16306 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16307 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16308 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16310 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16311 | |
| 16312 | // Start the first transaction to set up the SpdySession |
| 16313 | HttpRequestInfo request1; |
| 16314 | request1.method = "GET"; |
| 16315 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16316 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16317 | request1.traffic_annotation = |
| 16318 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16319 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16320 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16321 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16322 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16323 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16324 | data1.RunUntilPaused(); |
| 16325 | base::RunLoop().RunUntilIdle(); |
| 16326 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16327 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16328 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16329 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16330 | LoadTimingInfo load_timing_info1; |
| 16331 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16332 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16333 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16334 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16335 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16336 | HttpRequestInfo request2; |
| 16337 | request2.method = "GET"; |
| 16338 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16339 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16340 | request2.traffic_annotation = |
| 16341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16342 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16343 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16344 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16345 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16346 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16347 | data1.RunUntilPaused(); |
| 16348 | base::RunLoop().RunUntilIdle(); |
| 16349 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16350 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16351 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16352 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16353 | |
| 16354 | LoadTimingInfo load_timing_info2; |
| 16355 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16356 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16357 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16358 | // HTTP requests over a SPDY session should have a different connection |
| 16359 | // socket_log_id than requests over a tunnel. |
| 16360 | 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] | 16361 | } |
| 16362 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16363 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16364 | // that we do not pool other origins that resolve to the same IP when |
| 16365 | // the certificate does not match the new origin. |
| 16366 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16367 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16368 | const std::string url1 = "http://www.example.org/"; |
| 16369 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16370 | const std::string ip_addr = "1.2.3.4"; |
| 16371 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16372 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16373 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16374 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16375 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16376 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16377 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16378 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16379 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16380 | |
| 16381 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16382 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16383 | }; |
| 16384 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16385 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16386 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16387 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16388 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16389 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16390 | }; |
| 16391 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16392 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16393 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16394 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16395 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16396 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16397 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16398 | |
| 16399 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16400 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16401 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16402 | |
| 16403 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16404 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16405 | }; |
| 16406 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16407 | spdy::SpdySerializedFrame resp2( |
| 16408 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16409 | spdy::SpdySerializedFrame body2( |
| 16410 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16411 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16412 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16413 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16414 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16415 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16416 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16417 | |
| 16418 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16419 | // all others direct. |
| 16420 | ProxyConfig proxy_config; |
| 16421 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16422 | session_deps_.proxy_resolution_service = |
| 16423 | std::make_unique<ProxyResolutionService>( |
| 16424 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16425 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16426 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16427 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16428 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16429 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16430 | // Load a valid cert. Note, that this does not need to |
| 16431 | // be valid for proxy because the MockSSLClientSocket does |
| 16432 | // not actually verify it. But SpdySession will use this |
| 16433 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16434 | ssl1.ssl_info.cert = |
| 16435 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16436 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16438 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16439 | |
| 16440 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16441 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16442 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16443 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16444 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16445 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16446 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16447 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16448 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16449 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16450 | |
| 16451 | // Start the first transaction to set up the SpdySession |
| 16452 | HttpRequestInfo request1; |
| 16453 | request1.method = "GET"; |
| 16454 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16455 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16456 | request1.traffic_annotation = |
| 16457 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16458 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16459 | TestCompletionCallback callback1; |
| 16460 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16461 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16462 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16463 | data1.RunUntilPaused(); |
| 16464 | base::RunLoop().RunUntilIdle(); |
| 16465 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16466 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16467 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16468 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16469 | |
| 16470 | // Now, start the HTTP request |
| 16471 | HttpRequestInfo request2; |
| 16472 | request2.method = "GET"; |
| 16473 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16474 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16475 | request2.traffic_annotation = |
| 16476 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16477 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16478 | TestCompletionCallback callback2; |
| 16479 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16480 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16481 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16482 | |
| 16483 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16484 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16485 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16486 | } |
| 16487 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16488 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16489 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16490 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16491 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16492 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16493 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16494 | |
| 16495 | MockRead reads1[] = { |
| 16496 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16497 | }; |
| 16498 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16499 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16500 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16501 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16502 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16503 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16504 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16505 | }; |
| 16506 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16507 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16508 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16509 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16510 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16511 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16512 | }; |
| 16513 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16514 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16515 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16516 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16517 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16519 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16520 | |
| 16521 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16522 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16524 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16526 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16527 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16528 | |
| 16529 | // Start the first transaction to set up the SpdySession and verify that |
| 16530 | // connection was closed. |
| 16531 | HttpRequestInfo request1; |
| 16532 | request1.method = "GET"; |
| 16533 | request1.url = GURL(https_url); |
| 16534 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16535 | request1.traffic_annotation = |
| 16536 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16537 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16538 | TestCompletionCallback callback1; |
| 16539 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16540 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16541 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16542 | |
| 16543 | // Now, start the second request and make sure it succeeds. |
| 16544 | HttpRequestInfo request2; |
| 16545 | request2.method = "GET"; |
| 16546 | request2.url = GURL(https_url); |
| 16547 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16548 | request2.traffic_annotation = |
| 16549 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16550 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16551 | TestCompletionCallback callback2; |
| 16552 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16553 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16554 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16555 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16556 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16557 | } |
| 16558 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16559 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16560 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16561 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16562 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16563 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16564 | |
| 16565 | // Use two different hosts with different IPs so they don't get pooled. |
| 16566 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16567 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16569 | |
| 16570 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16571 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16572 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16573 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16574 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16576 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16577 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16578 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16579 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16580 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16581 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16582 | spdy::SpdySerializedFrame host1_resp( |
| 16583 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16584 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16585 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16586 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16587 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16588 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16589 | }; |
| 16590 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16591 | // Use a separate test instance for the separate SpdySession that will be |
| 16592 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16593 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16594 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16595 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16596 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16597 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16598 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16599 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16600 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16601 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16602 | spdy::SpdySerializedFrame host2_resp( |
| 16603 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16604 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16605 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16606 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16607 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16608 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16609 | }; |
| 16610 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16611 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16612 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16613 | |
| 16614 | MockWrite http_write[] = { |
| 16615 | MockWrite("GET / HTTP/1.1\r\n" |
| 16616 | "Host: www.a.com\r\n" |
| 16617 | "Connection: keep-alive\r\n\r\n"), |
| 16618 | }; |
| 16619 | |
| 16620 | MockRead http_read[] = { |
| 16621 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16622 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16623 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16624 | MockRead("hello!"), |
| 16625 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16626 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16627 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16628 | |
| 16629 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16630 | SpdySessionKey spdy_session_key_a( |
| 16631 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16632 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16633 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16634 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16635 | |
| 16636 | TestCompletionCallback callback; |
| 16637 | HttpRequestInfo request1; |
| 16638 | request1.method = "GET"; |
| 16639 | request1.url = GURL("https://www.a.com/"); |
| 16640 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16641 | request1.traffic_annotation = |
| 16642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16643 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16644 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16646 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16648 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16649 | |
| 16650 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16651 | ASSERT_TRUE(response); |
| 16652 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16653 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16654 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16655 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16656 | |
| 16657 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16658 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16659 | EXPECT_EQ("hello!", response_data); |
| 16660 | trans.reset(); |
| 16661 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16662 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16663 | |
| 16664 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16665 | SpdySessionKey spdy_session_key_b( |
| 16666 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16667 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16668 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16669 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16670 | HttpRequestInfo request2; |
| 16671 | request2.method = "GET"; |
| 16672 | request2.url = GURL("https://www.b.com/"); |
| 16673 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16674 | request2.traffic_annotation = |
| 16675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16676 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16677 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16679 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16681 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16682 | |
| 16683 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16684 | ASSERT_TRUE(response); |
| 16685 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16686 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16687 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16688 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16689 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16690 | EXPECT_EQ("hello!", response_data); |
| 16691 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16692 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16693 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16694 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16695 | |
| 16696 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16697 | SpdySessionKey spdy_session_key_a1( |
| 16698 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16699 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16700 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16701 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16702 | HttpRequestInfo request3; |
| 16703 | request3.method = "GET"; |
| 16704 | request3.url = GURL("http://www.a.com/"); |
| 16705 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16706 | request3.traffic_annotation = |
| 16707 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16708 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16709 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16710 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16711 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16713 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16714 | |
| 16715 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16716 | ASSERT_TRUE(response); |
| 16717 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16718 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16719 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16720 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16721 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16722 | EXPECT_EQ("hello!", response_data); |
| 16723 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16724 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16725 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16726 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16727 | } |
| 16728 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16729 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16730 | HttpRequestInfo request; |
| 16731 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16732 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16733 | request.traffic_annotation = |
| 16734 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16735 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16738 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16739 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16740 | StaticSocketDataProvider data; |
| 16741 | data.set_connect_data(mock_connect); |
| 16742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16743 | |
| 16744 | TestCompletionCallback callback; |
| 16745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16746 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16748 | |
| 16749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16750 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16751 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16752 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16753 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16754 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16755 | |
| 16756 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16757 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16758 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16759 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16760 | |
| 16761 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16762 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16763 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16764 | } |
| 16765 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16766 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16767 | HttpRequestInfo request; |
| 16768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16769 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16770 | request.traffic_annotation = |
| 16771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16772 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16775 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16776 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16777 | StaticSocketDataProvider data; |
| 16778 | data.set_connect_data(mock_connect); |
| 16779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16780 | |
| 16781 | TestCompletionCallback callback; |
| 16782 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16785 | |
| 16786 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16787 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16788 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16789 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16790 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16791 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16792 | |
| 16793 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16794 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16795 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16796 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16797 | |
| 16798 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16799 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16800 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16801 | } |
| 16802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16803 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16804 | HttpRequestInfo request; |
| 16805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16806 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16807 | request.traffic_annotation = |
| 16808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16812 | |
| 16813 | MockWrite data_writes[] = { |
| 16814 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16815 | }; |
| 16816 | MockRead data_reads[] = { |
| 16817 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16818 | }; |
| 16819 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16820 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16822 | |
| 16823 | TestCompletionCallback callback; |
| 16824 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16825 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16827 | |
| 16828 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16829 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16830 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16831 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16832 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16833 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16834 | } |
| 16835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16836 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16837 | HttpRequestInfo request; |
| 16838 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16839 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16840 | request.traffic_annotation = |
| 16841 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16842 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16845 | |
| 16846 | MockWrite data_writes[] = { |
| 16847 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16848 | }; |
| 16849 | MockRead data_reads[] = { |
| 16850 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16851 | }; |
| 16852 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16853 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16855 | |
| 16856 | TestCompletionCallback callback; |
| 16857 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16858 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16859 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16860 | |
| 16861 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16862 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16863 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16864 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16865 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16866 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16867 | } |
| 16868 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16869 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16870 | HttpRequestInfo request; |
| 16871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16872 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16873 | request.traffic_annotation = |
| 16874 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16875 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16877 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16878 | |
| 16879 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16880 | MockWrite( |
| 16881 | "GET / HTTP/1.1\r\n" |
| 16882 | "Host: www.example.org\r\n" |
| 16883 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16884 | }; |
| 16885 | MockRead data_reads[] = { |
| 16886 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16887 | }; |
| 16888 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16889 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16891 | |
| 16892 | TestCompletionCallback callback; |
| 16893 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16896 | |
| 16897 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16898 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16899 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16900 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16901 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16902 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16903 | } |
| 16904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16905 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16906 | HttpRequestInfo request; |
| 16907 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16908 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16909 | request.traffic_annotation = |
| 16910 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16911 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16912 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16913 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16914 | |
| 16915 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16916 | MockWrite( |
| 16917 | "GET / HTTP/1.1\r\n" |
| 16918 | "Host: www.example.org\r\n" |
| 16919 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16920 | }; |
| 16921 | MockRead data_reads[] = { |
| 16922 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16923 | }; |
| 16924 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16925 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16927 | |
| 16928 | TestCompletionCallback callback; |
| 16929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16932 | |
| 16933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16934 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16935 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16936 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16937 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16938 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16939 | } |
| 16940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16941 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16942 | HttpRequestInfo request; |
| 16943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16944 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16945 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16946 | request.traffic_annotation = |
| 16947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16951 | |
| 16952 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16953 | MockWrite( |
| 16954 | "GET / HTTP/1.1\r\n" |
| 16955 | "Host: www.example.org\r\n" |
| 16956 | "Connection: keep-alive\r\n" |
| 16957 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16958 | }; |
| 16959 | MockRead data_reads[] = { |
| 16960 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16961 | "Content-Length: 5\r\n\r\n" |
| 16962 | "hello"), |
| 16963 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16964 | }; |
| 16965 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16966 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16968 | |
| 16969 | TestCompletionCallback callback; |
| 16970 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16971 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16972 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16973 | |
| 16974 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16975 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16976 | |
| 16977 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16978 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16979 | std::string foo; |
| 16980 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16981 | EXPECT_EQ("bar", foo); |
| 16982 | } |
| 16983 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16984 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16985 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16986 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16987 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16988 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16989 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16990 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16991 | |
| 16992 | // Set up SSL request. |
| 16993 | |
| 16994 | HttpRequestInfo ssl_request; |
| 16995 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16996 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16997 | ssl_request.traffic_annotation = |
| 16998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16999 | |
| 17000 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17001 | MockWrite( |
| 17002 | "GET / HTTP/1.1\r\n" |
| 17003 | "Host: www.example.org\r\n" |
| 17004 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17005 | }; |
| 17006 | MockRead ssl_reads[] = { |
| 17007 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17008 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17009 | MockRead("hello world"), |
| 17010 | MockRead(SYNCHRONOUS, OK), |
| 17011 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17012 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17013 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17014 | |
| 17015 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17016 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17017 | |
| 17018 | // Set up HTTP request. |
| 17019 | |
| 17020 | HttpRequestInfo http_request; |
| 17021 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17022 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17023 | http_request.traffic_annotation = |
| 17024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17025 | |
| 17026 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17027 | MockWrite( |
| 17028 | "GET / HTTP/1.1\r\n" |
| 17029 | "Host: www.example.org\r\n" |
| 17030 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17031 | }; |
| 17032 | MockRead http_reads[] = { |
| 17033 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17034 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17035 | MockRead("falafel"), |
| 17036 | MockRead(SYNCHRONOUS, OK), |
| 17037 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17038 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17039 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17042 | |
| 17043 | // Start the SSL request. |
| 17044 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17045 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17046 | ASSERT_EQ(ERR_IO_PENDING, |
| 17047 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17048 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17049 | |
| 17050 | // Start the HTTP request. Pool should stall. |
| 17051 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17052 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17053 | ASSERT_EQ(ERR_IO_PENDING, |
| 17054 | http_trans.Start(&http_request, http_callback.callback(), |
| 17055 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17056 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17057 | |
| 17058 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17059 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17060 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17061 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17062 | EXPECT_EQ("hello world", response_data); |
| 17063 | |
| 17064 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17065 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17066 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17067 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17068 | |
| 17069 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17070 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17071 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17072 | EXPECT_EQ("falafel", response_data); |
| 17073 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17074 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17075 | } |
| 17076 | |
| 17077 | // Tests that when a SSL connection is established but there's no corresponding |
| 17078 | // request that needs it, the new socket is closed if the transport socket pool |
| 17079 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17080 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17081 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17082 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17083 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17084 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17085 | |
| 17086 | // Set up an ssl request. |
| 17087 | |
| 17088 | HttpRequestInfo ssl_request; |
| 17089 | ssl_request.method = "GET"; |
| 17090 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17091 | ssl_request.traffic_annotation = |
| 17092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17093 | |
| 17094 | // No data will be sent on the SSL socket. |
| 17095 | StaticSocketDataProvider ssl_data; |
| 17096 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17097 | |
| 17098 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17100 | |
| 17101 | // Set up HTTP request. |
| 17102 | |
| 17103 | HttpRequestInfo http_request; |
| 17104 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17105 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17106 | http_request.traffic_annotation = |
| 17107 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17108 | |
| 17109 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17110 | MockWrite( |
| 17111 | "GET / HTTP/1.1\r\n" |
| 17112 | "Host: www.example.org\r\n" |
| 17113 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17114 | }; |
| 17115 | MockRead http_reads[] = { |
| 17116 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17117 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17118 | MockRead("falafel"), |
| 17119 | MockRead(SYNCHRONOUS, OK), |
| 17120 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17121 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17122 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17125 | |
| 17126 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17127 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17128 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17129 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17130 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17131 | |
| 17132 | // Start the HTTP request. Pool should stall. |
| 17133 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17134 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17135 | ASSERT_EQ(ERR_IO_PENDING, |
| 17136 | http_trans.Start(&http_request, http_callback.callback(), |
| 17137 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17138 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17139 | |
| 17140 | // The SSL connection will automatically be closed once the connection is |
| 17141 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17142 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17143 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17144 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17145 | EXPECT_EQ("falafel", response_data); |
| 17146 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17147 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17148 | } |
| 17149 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17150 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17151 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17152 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17153 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17154 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17155 | |
| 17156 | HttpRequestInfo request; |
| 17157 | request.method = "POST"; |
| 17158 | request.url = GURL("http://www.foo.com/"); |
| 17159 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17160 | request.traffic_annotation = |
| 17161 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17162 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17165 | // Send headers successfully, but get an error while sending the body. |
| 17166 | MockWrite data_writes[] = { |
| 17167 | MockWrite("POST / HTTP/1.1\r\n" |
| 17168 | "Host: www.foo.com\r\n" |
| 17169 | "Connection: keep-alive\r\n" |
| 17170 | "Content-Length: 3\r\n\r\n"), |
| 17171 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17172 | }; |
| 17173 | |
| 17174 | MockRead data_reads[] = { |
| 17175 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17176 | MockRead("hello world"), |
| 17177 | MockRead(SYNCHRONOUS, OK), |
| 17178 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17179 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17181 | |
| 17182 | TestCompletionCallback callback; |
| 17183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17184 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17185 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17186 | |
| 17187 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17188 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17190 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17191 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17192 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17193 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17194 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17195 | |
| 17196 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17197 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17198 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17199 | EXPECT_EQ("hello world", response_data); |
| 17200 | } |
| 17201 | |
| 17202 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17203 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17204 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17205 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17207 | MockWrite data_writes[] = { |
| 17208 | MockWrite("GET / HTTP/1.1\r\n" |
| 17209 | "Host: www.foo.com\r\n" |
| 17210 | "Connection: keep-alive\r\n\r\n"), |
| 17211 | MockWrite("POST / HTTP/1.1\r\n" |
| 17212 | "Host: www.foo.com\r\n" |
| 17213 | "Connection: keep-alive\r\n" |
| 17214 | "Content-Length: 3\r\n\r\n"), |
| 17215 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17216 | }; |
| 17217 | |
| 17218 | MockRead data_reads[] = { |
| 17219 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17220 | "Content-Length: 14\r\n\r\n"), |
| 17221 | MockRead("first response"), |
| 17222 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17223 | "Content-Length: 15\r\n\r\n"), |
| 17224 | MockRead("second response"), |
| 17225 | MockRead(SYNCHRONOUS, OK), |
| 17226 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17227 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17228 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17229 | |
| 17230 | TestCompletionCallback callback; |
| 17231 | HttpRequestInfo request1; |
| 17232 | request1.method = "GET"; |
| 17233 | request1.url = GURL("http://www.foo.com/"); |
| 17234 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17235 | request1.traffic_annotation = |
| 17236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17237 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17238 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17239 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17240 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17242 | |
| 17243 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17245 | |
| 17246 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17247 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17248 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17249 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17250 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17251 | |
| 17252 | std::string response_data1; |
| 17253 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17254 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17255 | EXPECT_EQ("first response", response_data1); |
| 17256 | // Delete the transaction to release the socket back into the socket pool. |
| 17257 | trans1.reset(); |
| 17258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17259 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17260 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17261 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17262 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17263 | |
| 17264 | HttpRequestInfo request2; |
| 17265 | request2.method = "POST"; |
| 17266 | request2.url = GURL("http://www.foo.com/"); |
| 17267 | request2.upload_data_stream = &upload_data_stream; |
| 17268 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17269 | request2.traffic_annotation = |
| 17270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17272 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17273 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17275 | |
| 17276 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17277 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17279 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17280 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17281 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17282 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17283 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17284 | |
| 17285 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17286 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17287 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17288 | EXPECT_EQ("second response", response_data2); |
| 17289 | } |
| 17290 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17291 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17292 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17293 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17294 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17295 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17296 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17297 | |
| 17298 | HttpRequestInfo request; |
| 17299 | request.method = "POST"; |
| 17300 | request.url = GURL("http://www.foo.com/"); |
| 17301 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17302 | request.traffic_annotation = |
| 17303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17304 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17307 | // Send headers successfully, but get an error while sending the body. |
| 17308 | MockWrite data_writes[] = { |
| 17309 | MockWrite("POST / HTTP/1.1\r\n" |
| 17310 | "Host: www.foo.com\r\n" |
| 17311 | "Connection: keep-alive\r\n" |
| 17312 | "Content-Length: 3\r\n\r\n" |
| 17313 | "fo"), |
| 17314 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17315 | }; |
| 17316 | |
| 17317 | MockRead data_reads[] = { |
| 17318 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17319 | MockRead("hello world"), |
| 17320 | MockRead(SYNCHRONOUS, OK), |
| 17321 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17322 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17323 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17324 | |
| 17325 | TestCompletionCallback callback; |
| 17326 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17329 | |
| 17330 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17331 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17332 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17333 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17334 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17335 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17336 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17337 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17338 | |
| 17339 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17340 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17341 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17342 | EXPECT_EQ("hello world", response_data); |
| 17343 | } |
| 17344 | |
| 17345 | // This tests the more common case than the previous test, where headers and |
| 17346 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17347 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17348 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17349 | |
| 17350 | HttpRequestInfo request; |
| 17351 | request.method = "POST"; |
| 17352 | request.url = GURL("http://www.foo.com/"); |
| 17353 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17354 | request.traffic_annotation = |
| 17355 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17358 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17359 | // Send headers successfully, but get an error while sending the body. |
| 17360 | MockWrite data_writes[] = { |
| 17361 | MockWrite("POST / HTTP/1.1\r\n" |
| 17362 | "Host: www.foo.com\r\n" |
| 17363 | "Connection: keep-alive\r\n" |
| 17364 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17365 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17366 | }; |
| 17367 | |
| 17368 | MockRead data_reads[] = { |
| 17369 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17370 | MockRead("hello world"), |
| 17371 | MockRead(SYNCHRONOUS, OK), |
| 17372 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17373 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17375 | |
| 17376 | TestCompletionCallback callback; |
| 17377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17378 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17380 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17381 | // they can't be merged with the body in a single send. Not currently |
| 17382 | // necessary since a chunked body is never merged with headers, but this makes |
| 17383 | // the test more future proof. |
| 17384 | base::RunLoop().RunUntilIdle(); |
| 17385 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17386 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17387 | |
| 17388 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17389 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17391 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17392 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17393 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17394 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17395 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17396 | |
| 17397 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17398 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17399 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17400 | EXPECT_EQ("hello world", response_data); |
| 17401 | } |
| 17402 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17403 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17404 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17405 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17406 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17407 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17408 | |
| 17409 | HttpRequestInfo request; |
| 17410 | request.method = "POST"; |
| 17411 | request.url = GURL("http://www.foo.com/"); |
| 17412 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17413 | request.traffic_annotation = |
| 17414 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17415 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17416 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17418 | |
| 17419 | MockWrite data_writes[] = { |
| 17420 | MockWrite("POST / HTTP/1.1\r\n" |
| 17421 | "Host: www.foo.com\r\n" |
| 17422 | "Connection: keep-alive\r\n" |
| 17423 | "Content-Length: 3\r\n\r\n"), |
| 17424 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17425 | }; |
| 17426 | |
| 17427 | MockRead data_reads[] = { |
| 17428 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17429 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17430 | MockRead("hello world"), |
| 17431 | MockRead(SYNCHRONOUS, OK), |
| 17432 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17433 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17435 | |
| 17436 | TestCompletionCallback callback; |
| 17437 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17438 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17440 | |
| 17441 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17442 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17444 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17445 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17446 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17447 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17448 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17449 | |
| 17450 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17451 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17452 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17453 | EXPECT_EQ("hello world", response_data); |
| 17454 | } |
| 17455 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17456 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17457 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17458 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17459 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17460 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17461 | |
| 17462 | HttpRequestInfo request; |
| 17463 | request.method = "POST"; |
| 17464 | request.url = GURL("http://www.foo.com/"); |
| 17465 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17466 | request.traffic_annotation = |
| 17467 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17468 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17469 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17471 | // Send headers successfully, but get an error while sending the body. |
| 17472 | MockWrite data_writes[] = { |
| 17473 | MockWrite("POST / HTTP/1.1\r\n" |
| 17474 | "Host: www.foo.com\r\n" |
| 17475 | "Connection: keep-alive\r\n" |
| 17476 | "Content-Length: 3\r\n\r\n"), |
| 17477 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17478 | }; |
| 17479 | |
| 17480 | MockRead data_reads[] = { |
| 17481 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17482 | MockRead("hello world"), |
| 17483 | MockRead(SYNCHRONOUS, OK), |
| 17484 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17485 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17486 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17487 | |
| 17488 | TestCompletionCallback callback; |
| 17489 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17490 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17492 | |
| 17493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17494 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17495 | } |
| 17496 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17497 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17498 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17499 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17500 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17501 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17502 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17503 | |
| 17504 | HttpRequestInfo request; |
| 17505 | request.method = "POST"; |
| 17506 | request.url = GURL("http://www.foo.com/"); |
| 17507 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17508 | request.traffic_annotation = |
| 17509 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17510 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17512 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17513 | // Send headers successfully, but get an error while sending the body. |
| 17514 | MockWrite data_writes[] = { |
| 17515 | MockWrite("POST / HTTP/1.1\r\n" |
| 17516 | "Host: www.foo.com\r\n" |
| 17517 | "Connection: keep-alive\r\n" |
| 17518 | "Content-Length: 3\r\n\r\n"), |
| 17519 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17520 | }; |
| 17521 | |
| 17522 | MockRead data_reads[] = { |
| 17523 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17524 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17525 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17526 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17527 | MockRead(SYNCHRONOUS, OK), |
| 17528 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17529 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17531 | |
| 17532 | TestCompletionCallback callback; |
| 17533 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17534 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17535 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17536 | |
| 17537 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17538 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | } |
| 17540 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17541 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17542 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17543 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17544 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17545 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17546 | |
| 17547 | HttpRequestInfo request; |
| 17548 | request.method = "POST"; |
| 17549 | request.url = GURL("http://www.foo.com/"); |
| 17550 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17551 | request.traffic_annotation = |
| 17552 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17553 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17556 | // Send headers successfully, but get an error while sending the body. |
| 17557 | MockWrite data_writes[] = { |
| 17558 | MockWrite("POST / HTTP/1.1\r\n" |
| 17559 | "Host: www.foo.com\r\n" |
| 17560 | "Connection: keep-alive\r\n" |
| 17561 | "Content-Length: 3\r\n\r\n"), |
| 17562 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17563 | }; |
| 17564 | |
| 17565 | MockRead data_reads[] = { |
| 17566 | MockRead("HTTP 0.9 rocks!"), |
| 17567 | MockRead(SYNCHRONOUS, OK), |
| 17568 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17569 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17571 | |
| 17572 | TestCompletionCallback callback; |
| 17573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17574 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17576 | |
| 17577 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17578 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17579 | } |
| 17580 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17581 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17582 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17583 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17584 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17585 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17586 | |
| 17587 | HttpRequestInfo request; |
| 17588 | request.method = "POST"; |
| 17589 | request.url = GURL("http://www.foo.com/"); |
| 17590 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17591 | request.traffic_annotation = |
| 17592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17596 | // Send headers successfully, but get an error while sending the body. |
| 17597 | MockWrite data_writes[] = { |
| 17598 | MockWrite("POST / HTTP/1.1\r\n" |
| 17599 | "Host: www.foo.com\r\n" |
| 17600 | "Connection: keep-alive\r\n" |
| 17601 | "Content-Length: 3\r\n\r\n"), |
| 17602 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17603 | }; |
| 17604 | |
| 17605 | MockRead data_reads[] = { |
| 17606 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17607 | MockRead(SYNCHRONOUS, OK), |
| 17608 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17609 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17611 | |
| 17612 | TestCompletionCallback callback; |
| 17613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17616 | |
| 17617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17618 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17619 | } |
| 17620 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17621 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17622 | |
| 17623 | namespace { |
| 17624 | |
| 17625 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17626 | headers->SetHeader("Connection", "Upgrade"); |
| 17627 | headers->SetHeader("Upgrade", "websocket"); |
| 17628 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17629 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17630 | } |
| 17631 | |
| 17632 | } // namespace |
| 17633 | |
| 17634 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17635 | for (bool secure : {true, false}) { |
| 17636 | MockWrite data_writes[] = { |
| 17637 | MockWrite("GET / HTTP/1.1\r\n" |
| 17638 | "Host: www.example.org\r\n" |
| 17639 | "Connection: Upgrade\r\n" |
| 17640 | "Upgrade: websocket\r\n" |
| 17641 | "Origin: http://www.example.org\r\n" |
| 17642 | "Sec-WebSocket-Version: 13\r\n" |
| 17643 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17644 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17645 | "client_max_window_bits\r\n\r\n")}; |
| 17646 | |
| 17647 | MockRead data_reads[] = { |
| 17648 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17649 | "Upgrade: websocket\r\n" |
| 17650 | "Connection: Upgrade\r\n" |
| 17651 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17652 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17653 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17654 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17655 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17656 | if (secure) |
| 17657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17658 | |
| 17659 | HttpRequestInfo request; |
| 17660 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17661 | request.url = |
| 17662 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17663 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17664 | request.traffic_annotation = |
| 17665 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17666 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17667 | TestWebSocketHandshakeStreamCreateHelper |
| 17668 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17669 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17671 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17672 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17673 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17674 | |
| 17675 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17676 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17678 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17679 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17680 | ASSERT_TRUE(stream_request); |
| 17681 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17682 | stream_request->websocket_handshake_stream_create_helper()); |
| 17683 | |
| 17684 | rv = callback.WaitForResult(); |
| 17685 | EXPECT_THAT(rv, IsOk()); |
| 17686 | |
| 17687 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17688 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17689 | } |
| 17690 | } |
| 17691 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17692 | // Verify that proxy headers are not sent to the destination server when |
| 17693 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17694 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17695 | HttpRequestInfo request; |
| 17696 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17697 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17698 | request.traffic_annotation = |
| 17699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17700 | AddWebSocketHeaders(&request.extra_headers); |
| 17701 | |
| 17702 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17703 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17704 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17705 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17706 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17707 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17708 | |
| 17709 | // Since a proxy is configured, try to establish a tunnel. |
| 17710 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17711 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17712 | "Host: www.example.org:443\r\n" |
| 17713 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17714 | |
| 17715 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17716 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17717 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17718 | "Host: www.example.org:443\r\n" |
| 17719 | "Proxy-Connection: keep-alive\r\n" |
| 17720 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17721 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17722 | MockWrite("GET / HTTP/1.1\r\n" |
| 17723 | "Host: www.example.org\r\n" |
| 17724 | "Connection: Upgrade\r\n" |
| 17725 | "Upgrade: websocket\r\n" |
| 17726 | "Origin: http://www.example.org\r\n" |
| 17727 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17728 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17729 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17730 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17731 | |
| 17732 | // The proxy responds to the connect with a 407, using a persistent |
| 17733 | // connection. |
| 17734 | MockRead data_reads[] = { |
| 17735 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17736 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17737 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17738 | "Content-Length: 0\r\n" |
| 17739 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17740 | |
| 17741 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17742 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17743 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17744 | "Upgrade: websocket\r\n" |
| 17745 | "Connection: Upgrade\r\n" |
| 17746 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17747 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17748 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17749 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17750 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17752 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17753 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17754 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17755 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17756 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17757 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17758 | &websocket_stream_create_helper); |
| 17759 | |
| 17760 | { |
| 17761 | TestCompletionCallback callback; |
| 17762 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17763 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17765 | |
| 17766 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17767 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17768 | } |
| 17769 | |
| 17770 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17771 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17772 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17773 | EXPECT_EQ(407, response->headers->response_code()); |
| 17774 | |
| 17775 | { |
| 17776 | TestCompletionCallback callback; |
| 17777 | |
| 17778 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17779 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17781 | |
| 17782 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17783 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17784 | } |
| 17785 | |
| 17786 | response = trans->GetResponseInfo(); |
| 17787 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17788 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17789 | |
| 17790 | EXPECT_EQ(101, response->headers->response_code()); |
| 17791 | |
| 17792 | trans.reset(); |
| 17793 | session->CloseAllConnections(); |
| 17794 | } |
| 17795 | |
| 17796 | // Verify that proxy headers are not sent to the destination server when |
| 17797 | // establishing a tunnel for an insecure WebSocket connection. |
| 17798 | // This requires the authentication info to be injected into the auth cache |
| 17799 | // due to crbug.com/395064 |
| 17800 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17801 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17802 | HttpRequestInfo request; |
| 17803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17804 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17805 | request.traffic_annotation = |
| 17806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17807 | AddWebSocketHeaders(&request.extra_headers); |
| 17808 | |
| 17809 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17810 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17811 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17812 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17815 | |
| 17816 | MockWrite data_writes[] = { |
| 17817 | // Try to establish a tunnel for the WebSocket connection, with |
| 17818 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17819 | // they cannot and will not use the same TCP/IP connection as the |
| 17820 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17821 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17822 | "Host: www.example.org:80\r\n" |
| 17823 | "Proxy-Connection: keep-alive\r\n" |
| 17824 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17825 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17826 | MockWrite("GET / HTTP/1.1\r\n" |
| 17827 | "Host: www.example.org\r\n" |
| 17828 | "Connection: Upgrade\r\n" |
| 17829 | "Upgrade: websocket\r\n" |
| 17830 | "Origin: http://www.example.org\r\n" |
| 17831 | "Sec-WebSocket-Version: 13\r\n" |
| 17832 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17833 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17834 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17835 | |
| 17836 | MockRead data_reads[] = { |
| 17837 | // HTTP CONNECT with credentials. |
| 17838 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17839 | |
| 17840 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17841 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17842 | "Upgrade: websocket\r\n" |
| 17843 | "Connection: Upgrade\r\n" |
| 17844 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17845 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17846 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17848 | |
| 17849 | session->http_auth_cache()->Add( |
| 17850 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17851 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17852 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17853 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17854 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17855 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17856 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17857 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17858 | &websocket_stream_create_helper); |
| 17859 | |
| 17860 | TestCompletionCallback callback; |
| 17861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17862 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17864 | |
| 17865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17866 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17867 | |
| 17868 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17869 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17870 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17871 | |
| 17872 | EXPECT_EQ(101, response->headers->response_code()); |
| 17873 | |
| 17874 | trans.reset(); |
| 17875 | session->CloseAllConnections(); |
| 17876 | } |
| 17877 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17878 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17880 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17881 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17882 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17883 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17884 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17885 | |
| 17886 | HttpRequestInfo request; |
| 17887 | request.method = "POST"; |
| 17888 | request.url = GURL("http://www.foo.com/"); |
| 17889 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17890 | request.traffic_annotation = |
| 17891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17892 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17893 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17894 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17895 | MockWrite data_writes[] = { |
| 17896 | MockWrite("POST / HTTP/1.1\r\n" |
| 17897 | "Host: www.foo.com\r\n" |
| 17898 | "Connection: keep-alive\r\n" |
| 17899 | "Content-Length: 3\r\n\r\n"), |
| 17900 | MockWrite("foo"), |
| 17901 | }; |
| 17902 | |
| 17903 | MockRead data_reads[] = { |
| 17904 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17905 | MockRead(SYNCHRONOUS, OK), |
| 17906 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17907 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17909 | |
| 17910 | TestCompletionCallback callback; |
| 17911 | |
| 17912 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17913 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17914 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17915 | |
| 17916 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17917 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17918 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17919 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17920 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17921 | } |
| 17922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17923 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17924 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17925 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17926 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17927 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17928 | |
| 17929 | HttpRequestInfo request; |
| 17930 | request.method = "POST"; |
| 17931 | request.url = GURL("http://www.foo.com/"); |
| 17932 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17933 | request.traffic_annotation = |
| 17934 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17938 | MockWrite data_writes[] = { |
| 17939 | MockWrite("POST / HTTP/1.1\r\n" |
| 17940 | "Host: www.foo.com\r\n" |
| 17941 | "Connection: keep-alive\r\n" |
| 17942 | "Content-Length: 3\r\n\r\n"), |
| 17943 | MockWrite("foo"), |
| 17944 | }; |
| 17945 | |
| 17946 | MockRead data_reads[] = { |
| 17947 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17948 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17949 | MockRead(SYNCHRONOUS, OK), |
| 17950 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17951 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17952 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17953 | |
| 17954 | TestCompletionCallback callback; |
| 17955 | |
| 17956 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17957 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17958 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17959 | |
| 17960 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17961 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17962 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17963 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17964 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17965 | } |
| 17966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17967 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17968 | ChunkedUploadDataStream upload_data_stream(0); |
| 17969 | |
| 17970 | HttpRequestInfo request; |
| 17971 | request.method = "POST"; |
| 17972 | request.url = GURL("http://www.foo.com/"); |
| 17973 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17974 | request.traffic_annotation = |
| 17975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17976 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17978 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17979 | // Send headers successfully, but get an error while sending the body. |
| 17980 | MockWrite data_writes[] = { |
| 17981 | MockWrite("POST / HTTP/1.1\r\n" |
| 17982 | "Host: www.foo.com\r\n" |
| 17983 | "Connection: keep-alive\r\n" |
| 17984 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17985 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17986 | }; |
| 17987 | |
| 17988 | MockRead data_reads[] = { |
| 17989 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17990 | MockRead(SYNCHRONOUS, OK), |
| 17991 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17992 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17993 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17994 | |
| 17995 | TestCompletionCallback callback; |
| 17996 | |
| 17997 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17998 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17999 | |
| 18000 | base::RunLoop().RunUntilIdle(); |
| 18001 | upload_data_stream.AppendData("f", 1, false); |
| 18002 | |
| 18003 | base::RunLoop().RunUntilIdle(); |
| 18004 | upload_data_stream.AppendData("oo", 2, true); |
| 18005 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18006 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18007 | |
| 18008 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18009 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18010 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18011 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18012 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18013 | } |
| 18014 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18015 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18016 | const std::string& accept_encoding, |
| 18017 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18018 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18019 | bool should_match) { |
| 18020 | HttpRequestInfo request; |
| 18021 | request.method = "GET"; |
| 18022 | request.url = GURL("http://www.foo.com/"); |
| 18023 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18024 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18025 | request.traffic_annotation = |
| 18026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18027 | |
| 18028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18029 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18030 | // Send headers successfully, but get an error while sending the body. |
| 18031 | MockWrite data_writes[] = { |
| 18032 | MockWrite("GET / HTTP/1.1\r\n" |
| 18033 | "Host: www.foo.com\r\n" |
| 18034 | "Connection: keep-alive\r\n" |
| 18035 | "Accept-Encoding: "), |
| 18036 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18037 | }; |
| 18038 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18039 | std::string response_code = "200 OK"; |
| 18040 | std::string extra; |
| 18041 | if (!location.empty()) { |
| 18042 | response_code = "301 Redirect\r\nLocation: "; |
| 18043 | response_code.append(location); |
| 18044 | } |
| 18045 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18046 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18047 | MockRead("HTTP/1.0 "), |
| 18048 | MockRead(response_code.data()), |
| 18049 | MockRead("\r\nContent-Encoding: "), |
| 18050 | MockRead(content_encoding.data()), |
| 18051 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18052 | MockRead(SYNCHRONOUS, OK), |
| 18053 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18054 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18055 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18056 | |
| 18057 | TestCompletionCallback callback; |
| 18058 | |
| 18059 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18061 | |
| 18062 | rv = callback.WaitForResult(); |
| 18063 | if (should_match) { |
| 18064 | EXPECT_THAT(rv, IsOk()); |
| 18065 | } else { |
| 18066 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18067 | } |
| 18068 | } |
| 18069 | |
| 18070 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18071 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18072 | } |
| 18073 | |
| 18074 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18075 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18076 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18077 | } |
| 18078 | |
| 18079 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18080 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18081 | "", false); |
| 18082 | } |
| 18083 | |
| 18084 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18085 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18086 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18087 | } |
| 18088 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18089 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18090 | ProxyConfig proxy_config; |
| 18091 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18092 | proxy_config.set_pac_mandatory(true); |
| 18093 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18094 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18095 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18096 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18097 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18098 | |
| 18099 | HttpRequestInfo request; |
| 18100 | request.method = "GET"; |
| 18101 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18102 | request.traffic_annotation = |
| 18103 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18104 | |
| 18105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18106 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18107 | |
| 18108 | TestCompletionCallback callback; |
| 18109 | |
| 18110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18112 | EXPECT_THAT(callback.WaitForResult(), |
| 18113 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18114 | } |
| 18115 | |
| 18116 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18117 | ProxyConfig proxy_config; |
| 18118 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18119 | proxy_config.set_pac_mandatory(true); |
| 18120 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18121 | new MockAsyncProxyResolverFactory(false); |
| 18122 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18123 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18124 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18125 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18126 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18127 | HttpRequestInfo request; |
| 18128 | request.method = "GET"; |
| 18129 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18130 | request.traffic_annotation = |
| 18131 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18132 | |
| 18133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18134 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18135 | |
| 18136 | TestCompletionCallback callback; |
| 18137 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18139 | |
| 18140 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18141 | ERR_FAILED, &resolver); |
| 18142 | EXPECT_THAT(callback.WaitForResult(), |
| 18143 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18144 | } |
| 18145 | |
| 18146 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18147 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18148 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18149 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18150 | session_deps_.enable_quic = false; |
| 18151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18152 | |
| 18153 | HttpRequestInfo request; |
| 18154 | request.method = "GET"; |
| 18155 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18156 | request.traffic_annotation = |
| 18157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18158 | |
| 18159 | TestCompletionCallback callback; |
| 18160 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18161 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18163 | |
| 18164 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18165 | } |
| 18166 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18167 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18168 | // Reporting tests |
| 18169 | |
| 18170 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18171 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18172 | protected: |
| 18173 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18174 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18175 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18176 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18177 | test_reporting_context_ = test_reporting_context.get(); |
| 18178 | session_deps_.reporting_service = |
| 18179 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18180 | } |
| 18181 | |
| 18182 | TestReportingContext* reporting_context() const { |
| 18183 | return test_reporting_context_; |
| 18184 | } |
| 18185 | |
| 18186 | void clear_reporting_service() { |
| 18187 | session_deps_.reporting_service.reset(); |
| 18188 | test_reporting_context_ = nullptr; |
| 18189 | } |
| 18190 | |
| 18191 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18192 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18193 | HttpRequestInfo request; |
| 18194 | request.method = "GET"; |
| 18195 | request.url = GURL(url_); |
| 18196 | request.traffic_annotation = |
| 18197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18198 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18199 | MockRead data_reads[] = { |
| 18200 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18201 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18202 | "\"endpoints\": [{\"url\": " |
| 18203 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18204 | MockRead("\r\n"), |
| 18205 | MockRead("hello world"), |
| 18206 | MockRead(SYNCHRONOUS, OK), |
| 18207 | }; |
| 18208 | MockWrite data_writes[] = { |
| 18209 | MockWrite("GET / HTTP/1.1\r\n" |
| 18210 | "Host: www.example.org\r\n" |
| 18211 | "Connection: keep-alive\r\n\r\n"), |
| 18212 | }; |
| 18213 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18214 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18215 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18216 | |
| 18217 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18218 | if (request.url.SchemeIsCryptographic()) { |
| 18219 | ssl.ssl_info.cert = |
| 18220 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18221 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18222 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18224 | } |
| 18225 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18226 | TestCompletionCallback callback; |
| 18227 | auto session = CreateSession(&session_deps_); |
| 18228 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18229 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18230 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18231 | } |
| 18232 | |
| 18233 | protected: |
| 18234 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18235 | |
| 18236 | private: |
| 18237 | TestReportingContext* test_reporting_context_; |
| 18238 | }; |
| 18239 | |
| 18240 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18241 | DontProcessReportToHeaderNoService) { |
| 18242 | base::HistogramTester histograms; |
| 18243 | clear_reporting_service(); |
| 18244 | RequestPolicy(); |
| 18245 | histograms.ExpectBucketCount( |
| 18246 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18247 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18248 | } |
| 18249 | |
| 18250 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18251 | base::HistogramTester histograms; |
| 18252 | url_ = "http://www.example.org/"; |
| 18253 | RequestPolicy(); |
| 18254 | histograms.ExpectBucketCount( |
| 18255 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18256 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18257 | } |
| 18258 | |
| 18259 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18260 | RequestPolicy(); |
| 18261 | std::vector<const ReportingClient*> clients; |
| 18262 | reporting_context()->cache()->GetClients(&clients); |
| 18263 | ASSERT_EQ(1u, clients.size()); |
| 18264 | const auto* client = clients[0]; |
| 18265 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18266 | client->origin); |
| 18267 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18268 | EXPECT_EQ("nel", client->group); |
| 18269 | } |
| 18270 | |
| 18271 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18272 | DontProcessReportToHeaderInvalidHttps) { |
| 18273 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18274 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18275 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18276 | histograms.ExpectBucketCount( |
| 18277 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18278 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18279 | } |
| 18280 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18281 | |
| 18282 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18283 | // Network Error Logging tests |
| 18284 | |
| 18285 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18286 | namespace { |
| 18287 | |
| 18288 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18289 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18290 | |
| 18291 | } // namespace |
| 18292 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18293 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18294 | : public HttpNetworkTransactionTest { |
| 18295 | protected: |
| 18296 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18297 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18298 | auto network_error_logging_service = |
| 18299 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18300 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18301 | session_deps_.network_error_logging_service = |
| 18302 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18303 | |
| 18304 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18305 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18306 | |
| 18307 | request_.method = "GET"; |
| 18308 | request_.url = GURL(url_); |
| 18309 | request_.extra_headers = extra_headers_; |
| 18310 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18311 | request_.traffic_annotation = |
| 18312 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18313 | } |
| 18314 | |
| 18315 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18316 | return test_network_error_logging_service_; |
| 18317 | } |
| 18318 | |
| 18319 | void clear_network_error_logging_service() { |
| 18320 | session_deps_.network_error_logging_service.reset(); |
| 18321 | test_network_error_logging_service_ = nullptr; |
| 18322 | } |
| 18323 | |
| 18324 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18325 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18326 | std::string extra_header_string = extra_headers_.ToString(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18327 | MockRead data_reads[] = { |
| 18328 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18329 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18330 | MockRead("\r\n"), |
| 18331 | MockRead("hello world"), |
| 18332 | MockRead(SYNCHRONOUS, OK), |
| 18333 | }; |
| 18334 | MockWrite data_writes[] = { |
| 18335 | MockWrite("GET / HTTP/1.1\r\n" |
| 18336 | "Host: www.example.org\r\n" |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18337 | "Connection: keep-alive\r\n"), |
| 18338 | MockWrite(ASYNC, extra_header_string.data(), |
| 18339 | extra_header_string.size()), |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18340 | }; |
| 18341 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18342 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18343 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18344 | |
| 18345 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18346 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18347 | ssl.ssl_info.cert = |
| 18348 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18349 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18350 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18352 | } |
| 18353 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18354 | TestCompletionCallback callback; |
| 18355 | auto session = CreateSession(&session_deps_); |
| 18356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18357 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18358 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18359 | |
| 18360 | std::string response_data; |
| 18361 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18362 | EXPECT_EQ("hello world", response_data); |
| 18363 | } |
| 18364 | |
| 18365 | void CheckReport(size_t index, |
| 18366 | int status_code, |
| 18367 | int error_type, |
| 18368 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18369 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18370 | |
| 18371 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18372 | network_error_logging_service()->errors()[index]; |
| 18373 | EXPECT_EQ(url_, error.uri); |
| 18374 | EXPECT_EQ(kReferrer, error.referrer); |
| 18375 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18376 | EXPECT_EQ(server_ip, error.server_ip); |
| 18377 | EXPECT_EQ("http/1.1", error.protocol); |
| 18378 | EXPECT_EQ("GET", error.method); |
| 18379 | EXPECT_EQ(status_code, error.status_code); |
| 18380 | EXPECT_EQ(error_type, error.type); |
| 18381 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18382 | } |
| 18383 | |
| 18384 | protected: |
| 18385 | std::string url_ = "https://www.example.org/"; |
| 18386 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18387 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18388 | HttpRequestHeaders extra_headers_; |
| 18389 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18390 | |
| 18391 | private: |
| 18392 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18393 | }; |
| 18394 | |
| 18395 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18396 | DontProcessNelHeaderNoService) { |
| 18397 | base::HistogramTester histograms; |
| 18398 | clear_network_error_logging_service(); |
| 18399 | RequestPolicy(); |
| 18400 | histograms.ExpectBucketCount( |
| 18401 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18402 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18403 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18404 | 1); |
| 18405 | } |
| 18406 | |
| 18407 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18408 | DontProcessNelHeaderHttp) { |
| 18409 | base::HistogramTester histograms; |
| 18410 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18411 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18412 | RequestPolicy(); |
| 18413 | histograms.ExpectBucketCount( |
| 18414 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18415 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18416 | } |
| 18417 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18418 | // Don't set NEL policies received on a proxied connection. |
| 18419 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18420 | DontProcessNelHeaderProxy) { |
| 18421 | session_deps_.proxy_resolution_service = |
| 18422 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18423 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18424 | BoundTestNetLog log; |
| 18425 | session_deps_.net_log = log.bound().net_log(); |
| 18426 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18427 | |
| 18428 | HttpRequestInfo request; |
| 18429 | request.method = "GET"; |
| 18430 | request.url = GURL("https://www.example.org/"); |
| 18431 | request.traffic_annotation = |
| 18432 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18433 | |
| 18434 | // Since we have proxy, should try to establish tunnel. |
| 18435 | MockWrite data_writes1[] = { |
| 18436 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18437 | "Host: www.example.org:443\r\n" |
| 18438 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18439 | |
| 18440 | MockWrite("GET / HTTP/1.1\r\n" |
| 18441 | "Host: www.example.org\r\n" |
| 18442 | "Connection: keep-alive\r\n\r\n"), |
| 18443 | }; |
| 18444 | |
| 18445 | MockRead data_reads1[] = { |
| 18446 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18447 | |
| 18448 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18449 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18450 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18451 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18452 | MockRead(SYNCHRONOUS, OK), |
| 18453 | }; |
| 18454 | |
| 18455 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18456 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18457 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18458 | ssl.ssl_info.cert = |
| 18459 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18460 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18461 | ssl.ssl_info.cert_status = 0; |
| 18462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18463 | |
| 18464 | TestCompletionCallback callback1; |
| 18465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18466 | |
| 18467 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18469 | |
| 18470 | rv = callback1.WaitForResult(); |
| 18471 | EXPECT_THAT(rv, IsOk()); |
| 18472 | |
| 18473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18474 | ASSERT_TRUE(response); |
| 18475 | EXPECT_EQ(200, response->headers->response_code()); |
| 18476 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18477 | |
| 18478 | // No NEL header was set. |
| 18479 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18480 | } |
| 18481 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18482 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18483 | RequestPolicy(); |
| 18484 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18485 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18486 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18487 | header.origin); |
| 18488 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18489 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18490 | } |
| 18491 | |
| 18492 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18493 | DontProcessNelHeaderInvalidHttps) { |
| 18494 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18495 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18496 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18497 | histograms.ExpectBucketCount( |
| 18498 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18499 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18500 | 1); |
| 18501 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18502 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18503 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18504 | RequestPolicy(); |
| 18505 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18506 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18507 | } |
| 18508 | |
| 18509 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18510 | CreateReportErrorAfterStart) { |
| 18511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18512 | auto trans = |
| 18513 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18514 | |
| 18515 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18516 | StaticSocketDataProvider data; |
| 18517 | data.set_connect_data(mock_connect); |
| 18518 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18519 | |
| 18520 | TestCompletionCallback callback; |
| 18521 | |
| 18522 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18523 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18524 | |
| 18525 | trans.reset(); |
| 18526 | |
| 18527 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18528 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18529 | IPAddress() /* server_ip */); |
| 18530 | } |
| 18531 | |
| 18532 | // Same as above except the error is ASYNC |
| 18533 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18534 | CreateReportErrorAfterStartAsync) { |
| 18535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18536 | auto trans = |
| 18537 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18538 | |
| 18539 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18540 | StaticSocketDataProvider data; |
| 18541 | data.set_connect_data(mock_connect); |
| 18542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18543 | |
| 18544 | TestCompletionCallback callback; |
| 18545 | |
| 18546 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18547 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18548 | |
| 18549 | trans.reset(); |
| 18550 | |
| 18551 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18552 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18553 | IPAddress() /* server_ip */); |
| 18554 | } |
| 18555 | |
| 18556 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18557 | CreateReportReadBodyError) { |
| 18558 | std::string extra_header_string = extra_headers_.ToString(); |
| 18559 | MockRead data_reads[] = { |
| 18560 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18561 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18562 | MockRead("hello world"), |
| 18563 | MockRead(SYNCHRONOUS, OK), |
| 18564 | }; |
| 18565 | MockWrite data_writes[] = { |
| 18566 | MockWrite("GET / HTTP/1.1\r\n" |
| 18567 | "Host: www.example.org\r\n" |
| 18568 | "Connection: keep-alive\r\n"), |
| 18569 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18570 | }; |
| 18571 | |
| 18572 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18573 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18574 | |
| 18575 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18577 | |
| 18578 | // Log start time |
| 18579 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18580 | |
| 18581 | TestCompletionCallback callback; |
| 18582 | auto session = CreateSession(&session_deps_); |
| 18583 | auto trans = |
| 18584 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18585 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18586 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18587 | |
| 18588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18589 | ASSERT_TRUE(response); |
| 18590 | |
| 18591 | EXPECT_TRUE(response->headers); |
| 18592 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18593 | |
| 18594 | std::string response_data; |
| 18595 | rv = ReadTransaction(trans.get(), &response_data); |
| 18596 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18597 | |
| 18598 | trans.reset(); |
| 18599 | |
| 18600 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18601 | |
| 18602 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18603 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18604 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18605 | network_error_logging_service()->errors()[0]; |
| 18606 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18607 | } |
| 18608 | |
| 18609 | // Same as above except the final read is ASYNC. |
| 18610 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18611 | CreateReportReadBodyErrorAsync) { |
| 18612 | std::string extra_header_string = extra_headers_.ToString(); |
| 18613 | MockRead data_reads[] = { |
| 18614 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18615 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18616 | MockRead("hello world"), |
| 18617 | MockRead(ASYNC, OK), |
| 18618 | }; |
| 18619 | MockWrite data_writes[] = { |
| 18620 | MockWrite("GET / HTTP/1.1\r\n" |
| 18621 | "Host: www.example.org\r\n" |
| 18622 | "Connection: keep-alive\r\n"), |
| 18623 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18624 | }; |
| 18625 | |
| 18626 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18627 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18628 | |
| 18629 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18631 | |
| 18632 | // Log start time |
| 18633 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18634 | |
| 18635 | TestCompletionCallback callback; |
| 18636 | auto session = CreateSession(&session_deps_); |
| 18637 | auto trans = |
| 18638 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18639 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18640 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18641 | |
| 18642 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18643 | ASSERT_TRUE(response); |
| 18644 | |
| 18645 | EXPECT_TRUE(response->headers); |
| 18646 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18647 | |
| 18648 | std::string response_data; |
| 18649 | rv = ReadTransaction(trans.get(), &response_data); |
| 18650 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18651 | |
| 18652 | trans.reset(); |
| 18653 | |
| 18654 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18655 | |
| 18656 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18657 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18658 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18659 | network_error_logging_service()->errors()[0]; |
| 18660 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18661 | } |
| 18662 | |
| 18663 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18664 | CreateReportRestartWithAuth) { |
| 18665 | std::string extra_header_string = extra_headers_.ToString(); |
| 18666 | static const base::TimeDelta kSleepDuration = |
| 18667 | base::TimeDelta::FromMilliseconds(10); |
| 18668 | |
| 18669 | MockWrite data_writes1[] = { |
| 18670 | MockWrite("GET / HTTP/1.1\r\n" |
| 18671 | "Host: www.example.org\r\n" |
| 18672 | "Connection: keep-alive\r\n"), |
| 18673 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18674 | }; |
| 18675 | |
| 18676 | MockRead data_reads1[] = { |
| 18677 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18678 | // Give a couple authenticate options (only the middle one is actually |
| 18679 | // supported). |
| 18680 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18681 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18682 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18683 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18684 | // Large content-length -- won't matter, as connection will be reset. |
| 18685 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18686 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18687 | }; |
| 18688 | |
| 18689 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18690 | // be issuing -- the final header line contains the credentials. |
| 18691 | MockWrite data_writes2[] = { |
| 18692 | MockWrite("GET / HTTP/1.1\r\n" |
| 18693 | "Host: www.example.org\r\n" |
| 18694 | "Connection: keep-alive\r\n" |
| 18695 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18696 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18697 | }; |
| 18698 | |
| 18699 | // Lastly, the server responds with the actual content. |
| 18700 | MockRead data_reads2[] = { |
| 18701 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18702 | MockRead("hello world"), |
| 18703 | MockRead(SYNCHRONOUS, OK), |
| 18704 | }; |
| 18705 | |
| 18706 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18707 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18708 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18709 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18710 | |
| 18711 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18713 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18715 | |
| 18716 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18717 | base::TimeTicks restart_time; |
| 18718 | |
| 18719 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18720 | auto trans = |
| 18721 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18722 | |
| 18723 | TestCompletionCallback callback1; |
| 18724 | |
| 18725 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18726 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18727 | |
| 18728 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18729 | |
| 18730 | TestCompletionCallback callback2; |
| 18731 | |
| 18732 | // Wait 10 ms then restart with auth |
| 18733 | FastForwardBy(kSleepDuration); |
| 18734 | restart_time = base::TimeTicks::Now(); |
| 18735 | rv = |
| 18736 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18737 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18738 | |
| 18739 | std::string response_data; |
| 18740 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18741 | EXPECT_EQ("hello world", response_data); |
| 18742 | |
| 18743 | trans.reset(); |
| 18744 | |
| 18745 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18746 | // retry. Note that we don't report the error draining the body, as the first |
| 18747 | // request already generated a report for the auth challenge. |
| 18748 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18749 | |
| 18750 | // Check error report contents |
| 18751 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18752 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18753 | |
| 18754 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18755 | network_error_logging_service()->errors()[0]; |
| 18756 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18757 | network_error_logging_service()->errors()[1]; |
| 18758 | |
| 18759 | // Sanity-check elapsed time values |
| 18760 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18761 | // Check that the start time is refreshed when restarting with auth. |
| 18762 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18763 | } |
| 18764 | |
| 18765 | // Same as above, except draining the body before restarting fails |
| 18766 | // asynchronously. |
| 18767 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18768 | CreateReportRestartWithAuthAsync) { |
| 18769 | std::string extra_header_string = extra_headers_.ToString(); |
| 18770 | static const base::TimeDelta kSleepDuration = |
| 18771 | base::TimeDelta::FromMilliseconds(10); |
| 18772 | |
| 18773 | MockWrite data_writes1[] = { |
| 18774 | MockWrite("GET / HTTP/1.1\r\n" |
| 18775 | "Host: www.example.org\r\n" |
| 18776 | "Connection: keep-alive\r\n"), |
| 18777 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18778 | }; |
| 18779 | |
| 18780 | MockRead data_reads1[] = { |
| 18781 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18782 | // Give a couple authenticate options (only the middle one is actually |
| 18783 | // supported). |
| 18784 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18785 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18786 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18787 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18788 | // Large content-length -- won't matter, as connection will be reset. |
| 18789 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18790 | MockRead(ASYNC, ERR_FAILED), |
| 18791 | }; |
| 18792 | |
| 18793 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18794 | // be issuing -- the final header line contains the credentials. |
| 18795 | MockWrite data_writes2[] = { |
| 18796 | MockWrite("GET / HTTP/1.1\r\n" |
| 18797 | "Host: www.example.org\r\n" |
| 18798 | "Connection: keep-alive\r\n" |
| 18799 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18800 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18801 | }; |
| 18802 | |
| 18803 | // Lastly, the server responds with the actual content. |
| 18804 | MockRead data_reads2[] = { |
| 18805 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18806 | MockRead("hello world"), |
| 18807 | MockRead(SYNCHRONOUS, OK), |
| 18808 | }; |
| 18809 | |
| 18810 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18811 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18812 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18813 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18814 | |
| 18815 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18816 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18817 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18819 | |
| 18820 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18821 | base::TimeTicks restart_time; |
| 18822 | |
| 18823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18824 | auto trans = |
| 18825 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18826 | |
| 18827 | TestCompletionCallback callback1; |
| 18828 | |
| 18829 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18830 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18831 | |
| 18832 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18833 | |
| 18834 | TestCompletionCallback callback2; |
| 18835 | |
| 18836 | // Wait 10 ms then restart with auth |
| 18837 | FastForwardBy(kSleepDuration); |
| 18838 | restart_time = base::TimeTicks::Now(); |
| 18839 | rv = |
| 18840 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18841 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18842 | |
| 18843 | std::string response_data; |
| 18844 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18845 | EXPECT_EQ("hello world", response_data); |
| 18846 | |
| 18847 | trans.reset(); |
| 18848 | |
| 18849 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18850 | // retry. Note that we don't report the error draining the body, as the first |
| 18851 | // request already generated a report for the auth challenge. |
| 18852 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18853 | |
| 18854 | // Check error report contents |
| 18855 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18856 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18857 | |
| 18858 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18859 | network_error_logging_service()->errors()[0]; |
| 18860 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18861 | network_error_logging_service()->errors()[1]; |
| 18862 | |
| 18863 | // Sanity-check elapsed time values |
| 18864 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18865 | // Check that the start time is refreshed when restarting with auth. |
| 18866 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18867 | } |
| 18868 | |
| 18869 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18870 | CreateReportRetryKeepAliveConnectionReset) { |
| 18871 | std::string extra_header_string = extra_headers_.ToString(); |
| 18872 | MockWrite data_writes1[] = { |
| 18873 | MockWrite("GET / HTTP/1.1\r\n" |
| 18874 | "Host: www.example.org\r\n" |
| 18875 | "Connection: keep-alive\r\n"), |
| 18876 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18877 | MockWrite("GET / HTTP/1.1\r\n" |
| 18878 | "Host: www.example.org\r\n" |
| 18879 | "Connection: keep-alive\r\n"), |
| 18880 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18881 | }; |
| 18882 | |
| 18883 | MockRead data_reads1[] = { |
| 18884 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18885 | MockRead("hello"), |
| 18886 | // Connection is reset |
| 18887 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18888 | }; |
| 18889 | |
| 18890 | // Successful retry |
| 18891 | MockRead data_reads2[] = { |
| 18892 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18893 | MockRead("world"), |
| 18894 | MockRead(ASYNC, OK), |
| 18895 | }; |
| 18896 | |
| 18897 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18898 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18901 | |
| 18902 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18904 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18906 | |
| 18907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18908 | auto trans1 = |
| 18909 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18910 | |
| 18911 | TestCompletionCallback callback1; |
| 18912 | |
| 18913 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18914 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18915 | |
| 18916 | std::string response_data; |
| 18917 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18918 | EXPECT_EQ("hello", response_data); |
| 18919 | |
| 18920 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18921 | |
| 18922 | auto trans2 = |
| 18923 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18924 | |
| 18925 | TestCompletionCallback callback2; |
| 18926 | |
| 18927 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18928 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18929 | |
| 18930 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18931 | EXPECT_EQ("world", response_data); |
| 18932 | |
| 18933 | trans1.reset(); |
| 18934 | trans2.reset(); |
| 18935 | |
| 18936 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 18937 | // the second request, then an OK report from the successful retry. |
| 18938 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18939 | |
| 18940 | // Check error report contents |
| 18941 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18942 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 18943 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18944 | } |
| 18945 | |
| 18946 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18947 | CreateReportRetryKeepAlive408) { |
| 18948 | std::string extra_header_string = extra_headers_.ToString(); |
| 18949 | MockWrite data_writes1[] = { |
| 18950 | MockWrite("GET / HTTP/1.1\r\n" |
| 18951 | "Host: www.example.org\r\n" |
| 18952 | "Connection: keep-alive\r\n"), |
| 18953 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18954 | MockWrite("GET / HTTP/1.1\r\n" |
| 18955 | "Host: www.example.org\r\n" |
| 18956 | "Connection: keep-alive\r\n"), |
| 18957 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18958 | }; |
| 18959 | |
| 18960 | MockRead data_reads1[] = { |
| 18961 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18962 | MockRead("hello"), |
| 18963 | // 408 Request Timeout |
| 18964 | MockRead(SYNCHRONOUS, |
| 18965 | "HTTP/1.1 408 Request Timeout\r\n" |
| 18966 | "Connection: Keep-Alive\r\n" |
| 18967 | "Content-Length: 6\r\n\r\n" |
| 18968 | "Pickle"), |
| 18969 | }; |
| 18970 | |
| 18971 | // Successful retry |
| 18972 | MockRead data_reads2[] = { |
| 18973 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18974 | MockRead("world"), |
| 18975 | MockRead(ASYNC, OK), |
| 18976 | }; |
| 18977 | |
| 18978 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18979 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18980 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18981 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18982 | |
| 18983 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18985 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18987 | |
| 18988 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18989 | auto trans1 = |
| 18990 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18991 | |
| 18992 | TestCompletionCallback callback1; |
| 18993 | |
| 18994 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18995 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18996 | |
| 18997 | std::string response_data; |
| 18998 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18999 | EXPECT_EQ("hello", response_data); |
| 19000 | |
| 19001 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19002 | |
| 19003 | auto trans2 = |
| 19004 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19005 | |
| 19006 | TestCompletionCallback callback2; |
| 19007 | |
| 19008 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19009 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19010 | |
| 19011 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19012 | EXPECT_EQ("world", response_data); |
| 19013 | |
| 19014 | trans1.reset(); |
| 19015 | trans2.reset(); |
| 19016 | |
| 19017 | // One 200 report from first request, then a 408 report from |
| 19018 | // the second request, then a 200 report from the successful retry. |
| 19019 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19020 | |
| 19021 | // Check error report contents |
| 19022 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19023 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19024 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19025 | } |
| 19026 | |
| 19027 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19028 | CreateReportRetry421WithoutConnectionPooling) { |
| 19029 | // Two hosts resolve to the same IP address. |
| 19030 | const std::string ip_addr = "1.2.3.4"; |
| 19031 | IPAddress ip; |
| 19032 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19033 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19034 | |
| 19035 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19036 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19037 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19038 | |
| 19039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19040 | |
| 19041 | // Two requests on the first connection. |
| 19042 | spdy::SpdySerializedFrame req1( |
| 19043 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19044 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19045 | spdy::SpdySerializedFrame req2( |
| 19046 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19047 | spdy::SpdySerializedFrame rst( |
| 19048 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19049 | MockWrite writes1[] = { |
| 19050 | CreateMockWrite(req1, 0), |
| 19051 | CreateMockWrite(req2, 3), |
| 19052 | CreateMockWrite(rst, 6), |
| 19053 | }; |
| 19054 | |
| 19055 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19056 | spdy::SpdySerializedFrame resp1( |
| 19057 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19058 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19059 | spdy::SpdyHeaderBlock response_headers; |
| 19060 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19061 | spdy::SpdySerializedFrame resp2( |
| 19062 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19063 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19064 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19065 | |
| 19066 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19067 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19068 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19069 | |
| 19070 | AddSSLSocketData(); |
| 19071 | |
| 19072 | // Retry the second request on a second connection. |
| 19073 | SpdyTestUtil spdy_util2; |
| 19074 | spdy::SpdySerializedFrame req3( |
| 19075 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19076 | MockWrite writes2[] = { |
| 19077 | CreateMockWrite(req3, 0), |
| 19078 | }; |
| 19079 | |
| 19080 | spdy::SpdySerializedFrame resp3( |
| 19081 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19082 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19083 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19084 | MockRead(ASYNC, 0, 3)}; |
| 19085 | |
| 19086 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19087 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19088 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19089 | |
| 19090 | AddSSLSocketData(); |
| 19091 | |
| 19092 | // Preload mail.example.org into HostCache. |
| 19093 | HostPortPair host_port("mail.example.org", 443); |
| 19094 | HostResolver::RequestInfo resolve_info(host_port); |
| 19095 | AddressList ignored; |
| 19096 | std::unique_ptr<HostResolver::Request> request; |
| 19097 | TestCompletionCallback callback; |
| 19098 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 19099 | &ignored, callback.callback(), |
| 19100 | &request, NetLogWithSource()); |
| 19101 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19102 | |
| 19103 | HttpRequestInfo request1; |
| 19104 | request1.method = "GET"; |
| 19105 | request1.url = GURL("https://www.example.org/"); |
| 19106 | request1.load_flags = 0; |
| 19107 | request1.traffic_annotation = |
| 19108 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19109 | auto trans1 = |
| 19110 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19111 | |
| 19112 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19113 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19114 | |
| 19115 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19116 | ASSERT_TRUE(response); |
| 19117 | ASSERT_TRUE(response->headers); |
| 19118 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19119 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19120 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19121 | std::string response_data; |
| 19122 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19123 | EXPECT_EQ("hello!", response_data); |
| 19124 | |
| 19125 | trans1.reset(); |
| 19126 | |
| 19127 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19128 | |
| 19129 | HttpRequestInfo request2; |
| 19130 | request2.method = "GET"; |
| 19131 | request2.url = GURL("https://mail.example.org/"); |
| 19132 | request2.load_flags = 0; |
| 19133 | request2.traffic_annotation = |
| 19134 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19135 | auto trans2 = |
| 19136 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19137 | |
| 19138 | BoundTestNetLog log; |
| 19139 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19140 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19141 | |
| 19142 | response = trans2->GetResponseInfo(); |
| 19143 | ASSERT_TRUE(response); |
| 19144 | ASSERT_TRUE(response->headers); |
| 19145 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19146 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19147 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19148 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19149 | EXPECT_EQ("hello!", response_data); |
| 19150 | |
| 19151 | trans2.reset(); |
| 19152 | |
| 19153 | // One 200 report from the first request, then a 421 report from the |
| 19154 | // second request, then a 200 report from the successful retry. |
| 19155 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19156 | |
| 19157 | // Check error report contents |
| 19158 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19159 | network_error_logging_service()->errors()[0]; |
| 19160 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19161 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19162 | EXPECT_EQ("", error1.user_agent); |
| 19163 | EXPECT_EQ(ip, error1.server_ip); |
| 19164 | EXPECT_EQ("h2", error1.protocol); |
| 19165 | EXPECT_EQ("GET", error1.method); |
| 19166 | EXPECT_EQ(200, error1.status_code); |
| 19167 | EXPECT_EQ(OK, error1.type); |
| 19168 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19169 | |
| 19170 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19171 | network_error_logging_service()->errors()[1]; |
| 19172 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19173 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19174 | EXPECT_EQ("", error2.user_agent); |
| 19175 | EXPECT_EQ(ip, error2.server_ip); |
| 19176 | EXPECT_EQ("h2", error2.protocol); |
| 19177 | EXPECT_EQ("GET", error2.method); |
| 19178 | EXPECT_EQ(421, error2.status_code); |
| 19179 | EXPECT_EQ(OK, error2.type); |
| 19180 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19181 | |
| 19182 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19183 | network_error_logging_service()->errors()[2]; |
| 19184 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19185 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19186 | EXPECT_EQ("", error3.user_agent); |
| 19187 | EXPECT_EQ(ip, error3.server_ip); |
| 19188 | EXPECT_EQ("h2", error3.protocol); |
| 19189 | EXPECT_EQ("GET", error3.method); |
| 19190 | EXPECT_EQ(200, error3.status_code); |
| 19191 | EXPECT_EQ(OK, error3.type); |
| 19192 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19193 | } |
| 19194 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19195 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19196 | base::HistogramTester histograms; |
| 19197 | RequestPolicy(); |
| 19198 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19199 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19200 | |
| 19201 | // Make HTTP request |
| 19202 | std::string extra_header_string = extra_headers_.ToString(); |
| 19203 | MockRead data_reads[] = { |
| 19204 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19205 | MockRead("hello world"), |
| 19206 | MockRead(SYNCHRONOUS, OK), |
| 19207 | }; |
| 19208 | MockWrite data_writes[] = { |
| 19209 | MockWrite("GET / HTTP/1.1\r\n" |
| 19210 | "Host: www.example.org\r\n" |
| 19211 | "Connection: keep-alive\r\n"), |
| 19212 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19213 | }; |
| 19214 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19215 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19216 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19217 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19218 | // Insecure url |
| 19219 | url_ = "http://www.example.org/"; |
| 19220 | request_.url = GURL(url_); |
| 19221 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19222 | TestCompletionCallback callback; |
| 19223 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19224 | auto trans = |
| 19225 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19226 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19227 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19228 | |
| 19229 | std::string response_data; |
| 19230 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19231 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19232 | |
| 19233 | // Insecure request does not generate a report |
| 19234 | histograms.ExpectBucketCount( |
| 19235 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19236 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19237 | |
| 19238 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19239 | } |
| 19240 | |
| 19241 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19242 | DontCreateReportHttpError) { |
| 19243 | base::HistogramTester histograms; |
| 19244 | RequestPolicy(); |
| 19245 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19246 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19247 | |
| 19248 | // Make HTTP request that fails |
| 19249 | MockRead data_reads[] = { |
| 19250 | MockRead("hello world"), |
| 19251 | MockRead(SYNCHRONOUS, OK), |
| 19252 | }; |
| 19253 | |
| 19254 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19256 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19257 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19258 | request_.url = GURL(url_); |
| 19259 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19261 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19262 | auto trans = |
| 19263 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19264 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19265 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19266 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19267 | |
| 19268 | // Insecure request does not generate a report, regardless of existence of a |
| 19269 | // policy for the origin. |
| 19270 | histograms.ExpectBucketCount( |
| 19271 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19272 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19273 | |
| 19274 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19275 | } |
| 19276 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19277 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19278 | // proxy. |
| 19279 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19280 | HttpRequestInfo request; |
| 19281 | request.method = "GET"; |
| 19282 | request.url = GURL("https://www.example.org/"); |
| 19283 | request.traffic_annotation = |
| 19284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19285 | |
| 19286 | // Configure against proxy server "myproxy:70". |
| 19287 | session_deps_.proxy_resolution_service = |
| 19288 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19289 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19291 | |
| 19292 | // Since we have proxy, should try to establish tunnel. |
| 19293 | MockWrite data_writes1[] = { |
| 19294 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19295 | "Host: www.example.org:443\r\n" |
| 19296 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19297 | }; |
| 19298 | |
| 19299 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19300 | // connection. |
| 19301 | MockRead data_reads1[] = { |
| 19302 | // No credentials. |
| 19303 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19304 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19305 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19306 | }; |
| 19307 | |
| 19308 | MockWrite data_writes2[] = { |
| 19309 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19310 | // be issuing -- the final header line contains the credentials. |
| 19311 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19312 | "Host: www.example.org:443\r\n" |
| 19313 | "Proxy-Connection: keep-alive\r\n" |
| 19314 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19315 | |
| 19316 | MockWrite("GET / HTTP/1.1\r\n" |
| 19317 | "Host: www.example.org\r\n" |
| 19318 | "Connection: keep-alive\r\n\r\n"), |
| 19319 | }; |
| 19320 | |
| 19321 | MockRead data_reads2[] = { |
| 19322 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19323 | |
| 19324 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19325 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19326 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19327 | MockRead(SYNCHRONOUS, "hello"), |
| 19328 | }; |
| 19329 | |
| 19330 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19331 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19332 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19333 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19334 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19336 | |
| 19337 | TestCompletionCallback callback1; |
| 19338 | |
| 19339 | auto trans = |
| 19340 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19341 | |
| 19342 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19343 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19344 | |
| 19345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19346 | EXPECT_EQ(407, response->headers->response_code()); |
| 19347 | |
| 19348 | std::string response_data; |
| 19349 | rv = ReadTransaction(trans.get(), &response_data); |
| 19350 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19351 | |
| 19352 | // No NEL report is generated for the 407. |
| 19353 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19354 | |
| 19355 | TestCompletionCallback callback2; |
| 19356 | |
| 19357 | rv = |
| 19358 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19359 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19360 | |
| 19361 | response = trans->GetResponseInfo(); |
| 19362 | EXPECT_EQ(200, response->headers->response_code()); |
| 19363 | |
| 19364 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19365 | EXPECT_EQ("hello", response_data); |
| 19366 | |
| 19367 | trans.reset(); |
| 19368 | |
| 19369 | // No NEL report is generated because we are behind a proxy. |
| 19370 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19371 | } |
| 19372 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19373 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19374 | ReportContainsUploadDepth) { |
| 19375 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19376 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19377 | RequestPolicy(); |
| 19378 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19379 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19380 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19381 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19382 | } |
| 19383 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19384 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19385 | std::string extra_header_string = extra_headers_.ToString(); |
| 19386 | static const base::TimeDelta kSleepDuration = |
| 19387 | base::TimeDelta::FromMilliseconds(10); |
| 19388 | |
| 19389 | std::vector<MockWrite> data_writes = { |
| 19390 | MockWrite(ASYNC, 0, |
| 19391 | "GET / HTTP/1.1\r\n" |
| 19392 | "Host: www.example.org\r\n" |
| 19393 | "Connection: keep-alive\r\n"), |
| 19394 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19395 | }; |
| 19396 | |
| 19397 | std::vector<MockRead> data_reads = { |
| 19398 | // Write one byte of the status line, followed by a pause. |
| 19399 | MockRead(ASYNC, 2, "H"), |
| 19400 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19401 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19402 | MockRead(ASYNC, 5, "hello world"), |
| 19403 | MockRead(SYNCHRONOUS, OK, 6), |
| 19404 | }; |
| 19405 | |
| 19406 | SequencedSocketData data(data_reads, data_writes); |
| 19407 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19408 | |
| 19409 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19411 | |
| 19412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19413 | |
| 19414 | auto trans = |
| 19415 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19416 | |
| 19417 | TestCompletionCallback callback; |
| 19418 | |
| 19419 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19421 | |
| 19422 | data.RunUntilPaused(); |
| 19423 | ASSERT_TRUE(data.IsPaused()); |
| 19424 | FastForwardBy(kSleepDuration); |
| 19425 | data.Resume(); |
| 19426 | |
| 19427 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19428 | |
| 19429 | std::string response_data; |
| 19430 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19431 | EXPECT_EQ("hello world", response_data); |
| 19432 | |
| 19433 | trans.reset(); |
| 19434 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19435 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19436 | |
| 19437 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19438 | |
| 19439 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19440 | network_error_logging_service()->errors()[0]; |
| 19441 | |
| 19442 | // Sanity-check elapsed time in error report |
| 19443 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19444 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19445 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19446 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19447 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19448 | } // namespace net |