[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" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 25 | #include "base/optional.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 26 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 30 | #include "base/strings/stringprintf.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 32 | #include "base/test/metrics/histogram_tester.h" |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 33 | #include "base/test/scoped_task_environment.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 34 | #include "base/test/simple_test_clock.h" |
| 35 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 36 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 37 | #include "base/threading/thread_task_runner_handle.h" |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame^] | 38 | #include "build/build_config.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 39 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 40 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 41 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 42 | #include "net/base/elements_upload_data_stream.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 43 | #include "net/base/host_port_pair.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 44 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 45 | #include "net/base/load_timing_info.h" |
| 46 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/base/net_errors.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 48 | #include "net/base/privacy_mode.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 49 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 50 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 51 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 52 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 53 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 54 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 55 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 56 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 57 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 58 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 59 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 60 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 61 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 62 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 63 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 64 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 65 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 66 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 67 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 68 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 69 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 70 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 71 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 72 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 73 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 74 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 75 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 76 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 77 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 78 | #include "net/log/test_net_log_entry.h" |
| 79 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 80 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 81 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 82 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 83 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 84 | #include "net/proxy_resolution/proxy_resolver.h" |
| 85 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 86 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 87 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 88 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 89 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 90 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 91 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 92 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 93 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 94 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 95 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 96 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 97 | #include "net/spdy/spdy_session.h" |
| 98 | #include "net/spdy/spdy_session_pool.h" |
| 99 | #include "net/spdy/spdy_test_util_common.h" |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 100 | #include "net/ssl/client_cert_identity_test_util.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 101 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 102 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 103 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 104 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 105 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 106 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 107 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 108 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 109 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 110 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 111 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 112 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 113 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 114 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 115 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 116 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 117 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 118 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 119 | #if defined(NTLM_PORTABLE) |
| 120 | #include "base/base64.h" |
| 121 | #include "net/ntlm/ntlm_test_data.h" |
| 122 | #endif |
| 123 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 124 | #if BUILDFLAG(ENABLE_REPORTING) |
| 125 | #include "net/network_error_logging/network_error_logging_service.h" |
| 126 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 127 | #include "net/reporting/reporting_cache.h" |
| 128 | #include "net/reporting/reporting_client.h" |
| 129 | #include "net/reporting/reporting_header_parser.h" |
| 130 | #include "net/reporting/reporting_service.h" |
| 131 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 132 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 133 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 134 | using net::test::IsError; |
| 135 | using net::test::IsOk; |
| 136 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 137 | using base::ASCIIToUTF16; |
| 138 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 139 | using testing::AnyOf; |
| 140 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 141 | //----------------------------------------------------------------------------- |
| 142 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 143 | namespace net { |
| 144 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 145 | namespace { |
| 146 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 147 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 148 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 149 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 150 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 151 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 152 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 153 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 154 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 155 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 156 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 157 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 158 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 159 | const char kAlternativeServiceHttpHeader[] = |
| 160 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 161 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 162 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 163 | return session |
| 164 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 165 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 166 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 167 | } |
| 168 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 169 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 170 | return session |
| 171 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 172 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 173 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 174 | } |
| 175 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 176 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 177 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 178 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 179 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 180 | if (!params) |
| 181 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 182 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 183 | if (!params->GetList("headers", &header_list)) |
| 184 | return false; |
| 185 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 186 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 187 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 188 | return true; |
| 189 | } |
| 190 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 192 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 193 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 195 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 196 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 198 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 199 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 200 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 201 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 202 | |
| 203 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 204 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 205 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 206 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 207 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 208 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 212 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 213 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 214 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 216 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | |
| 218 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 219 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 220 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 221 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 222 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 224 | load_timing_info.send_start); |
| 225 | |
| 226 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 228 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 230 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 231 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 235 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 236 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 238 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 239 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 240 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | |
| 242 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 243 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 244 | load_timing_info.proxy_resolve_end); |
| 245 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 246 | load_timing_info.send_start); |
| 247 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 248 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 249 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 250 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 251 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 252 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 256 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 257 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 258 | int connect_timing_flags) { |
| 259 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 260 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | |
| 262 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 263 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 264 | load_timing_info.proxy_resolve_end); |
| 265 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 266 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 267 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 268 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 270 | load_timing_info.send_start); |
| 271 | |
| 272 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 273 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 274 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 275 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 276 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 277 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 278 | } |
| 279 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 280 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 281 | // result to return. |
| 282 | class CapturingProxyResolver : public ProxyResolver { |
| 283 | public: |
| 284 | CapturingProxyResolver() |
| 285 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 286 | ~CapturingProxyResolver() override = default; |
| 287 | |
| 288 | int GetProxyForURL(const GURL& url, |
| 289 | ProxyInfo* results, |
| 290 | CompletionOnceCallback callback, |
| 291 | std::unique_ptr<Request>* request, |
| 292 | const NetLogWithSource& net_log) override { |
| 293 | results->UseProxyServer(proxy_server_); |
| 294 | resolved_.push_back(url); |
| 295 | return OK; |
| 296 | } |
| 297 | |
| 298 | // Sets whether the resolver should use direct connections, instead of a |
| 299 | // proxy. |
| 300 | void set_proxy_server(ProxyServer proxy_server) { |
| 301 | proxy_server_ = proxy_server; |
| 302 | } |
| 303 | |
| 304 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 305 | |
| 306 | private: |
| 307 | std::vector<GURL> resolved_; |
| 308 | |
| 309 | ProxyServer proxy_server_; |
| 310 | |
| 311 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 312 | }; |
| 313 | |
| 314 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 315 | public: |
| 316 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 317 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 318 | |
| 319 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 320 | std::unique_ptr<ProxyResolver>* resolver, |
| 321 | CompletionOnceCallback callback, |
| 322 | std::unique_ptr<Request>* request) override { |
| 323 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 324 | return OK; |
| 325 | } |
| 326 | |
| 327 | private: |
| 328 | ProxyResolver* resolver_; |
| 329 | }; |
| 330 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 331 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 332 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 333 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 334 | } |
| 335 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 336 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 337 | public: |
| 338 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 339 | |
| 340 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 341 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 342 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 343 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 344 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 345 | return ERR_PAC_SCRIPT_FAILED; |
| 346 | } |
| 347 | }; |
| 348 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 349 | class TestSSLConfigService : public SSLConfigService { |
| 350 | public: |
| 351 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 352 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 353 | |
| 354 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 355 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 356 | bool CanShareConnectionWithClientCerts( |
| 357 | const std::string& hostname) const override { |
| 358 | return false; |
| 359 | } |
| 360 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 361 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 362 | SSLConfig config_; |
| 363 | }; |
| 364 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 365 | } // namespace |
| 366 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 367 | class HttpNetworkTransactionTest : public PlatformTest, |
| 368 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 369 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 370 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 371 | // Important to restore the per-pool limit first, since the pool limit must |
| 372 | // always be greater than group limit, and the tests reduce both limits. |
| 373 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 374 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 375 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 376 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 377 | } |
| 378 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 379 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 380 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 381 | : WithScopedTaskEnvironment( |
| 382 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 383 | base::test::ScopedTaskEnvironment::NowSource:: |
| 384 | MAIN_THREAD_MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 385 | dummy_connect_job_params_( |
| 386 | nullptr /* client_socket_factory */, |
| 387 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 388 | nullptr /* http_auth_cache */, |
| 389 | nullptr /* http_auth_handler_factory */, |
| 390 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 391 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 392 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 393 | nullptr /* proxy_delegate */, |
| 394 | nullptr /* http_user_agent_settings */, |
| 395 | SSLClientSocketContext(), |
| 396 | SSLClientSocketContext(), |
| 397 | nullptr /* socket_performance_watcher_factory */, |
| 398 | nullptr /* network_quality_estimator */, |
| 399 | nullptr /* net_log */, |
| 400 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 401 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 402 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 403 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 404 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 405 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 406 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 407 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 408 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 409 | struct SimpleGetHelperResult { |
| 410 | int rv; |
| 411 | std::string status_line; |
| 412 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 413 | int64_t total_received_bytes; |
| 414 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 415 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 416 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 417 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 418 | }; |
| 419 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 420 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 421 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 422 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 423 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 424 | // before incrementing the counter does not return a null value. |
| 425 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 426 | } |
| 427 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 428 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 429 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 430 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 431 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 432 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 433 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 434 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 435 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 436 | } |
| 437 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 438 | void Check100ResponseTiming(bool use_spdy); |
| 439 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 440 | // Either |write_failure| specifies a write failure or |read_failure| |
| 441 | // specifies a read failure when using a reused socket. In either case, the |
| 442 | // failure should cause the network transaction to resend the request, and the |
| 443 | // other argument should be NULL. |
| 444 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 445 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 446 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 447 | // Either |write_failure| specifies a write failure or |read_failure| |
| 448 | // specifies a read failure when using a reused socket. In either case, the |
| 449 | // failure should cause the network transaction to resend the request, and the |
| 450 | // other argument should be NULL. |
| 451 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 452 | const MockRead* read_failure, |
| 453 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 454 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 455 | SimpleGetHelperResult SimpleGetHelperForData( |
| 456 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 457 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 458 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 459 | HttpRequestInfo request; |
| 460 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 461 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 462 | request.traffic_annotation = |
| 463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 464 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 465 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 466 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 467 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 469 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 470 | for (auto* provider : providers) { |
| 471 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 472 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 474 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 475 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 476 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 477 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 479 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 480 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 481 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 482 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 483 | |
| 484 | // Even in the failure cases that use this function, connections are always |
| 485 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 486 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 487 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 488 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 489 | if (out.rv != OK) |
| 490 | return out; |
| 491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 492 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 493 | // Can't use ASSERT_* inside helper functions like this, so |
| 494 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 495 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 496 | out.rv = ERR_UNEXPECTED; |
| 497 | return out; |
| 498 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 499 | out.status_line = response->headers->GetStatusLine(); |
| 500 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 501 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 502 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 503 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 504 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 505 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 506 | EXPECT_EQ(got_endpoint, |
| 507 | out.remote_endpoint_after_start.address().size() > 0); |
| 508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 509 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 511 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 512 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 513 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 514 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 515 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 516 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 517 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 518 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 519 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 520 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 521 | std::string line; |
| 522 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 523 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 524 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 525 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 526 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 527 | std::string value; |
| 528 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 529 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 530 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 531 | EXPECT_EQ("keep-alive", value); |
| 532 | |
| 533 | std::string response_headers; |
| 534 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 535 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 536 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 538 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 539 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 540 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 542 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 543 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 544 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 545 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 546 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 547 | MockWrite data_writes[] = { |
| 548 | MockWrite("GET / HTTP/1.1\r\n" |
| 549 | "Host: www.example.org\r\n" |
| 550 | "Connection: keep-alive\r\n\r\n"), |
| 551 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 552 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 553 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 554 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 555 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 556 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 557 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 558 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 559 | } |
| 560 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 561 | void AddSSLSocketData() { |
| 562 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 563 | ssl_.ssl_info.cert = |
| 564 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 565 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 567 | } |
| 568 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 569 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 570 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 571 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 572 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 573 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 574 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 575 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 576 | const CommonConnectJobParams dummy_connect_job_params_; |
| 577 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 578 | // These clocks are defined here, even though they're only used in the |
| 579 | // Reporting tests below, since they need to be destroyed after |
| 580 | // |session_deps_|. |
| 581 | base::SimpleTestClock clock_; |
| 582 | base::SimpleTestTickClock tick_clock_; |
| 583 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 584 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 585 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 586 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 587 | |
| 588 | // Original socket limits. Some tests set these. Safest to always restore |
| 589 | // them once each test has been run. |
| 590 | int old_max_group_sockets_; |
| 591 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 592 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 593 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 594 | namespace { |
| 595 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 596 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 597 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 598 | BeforeHeadersSentHandler() |
| 599 | : observed_before_headers_sent_with_proxy_(false), |
| 600 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 602 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 603 | HttpRequestHeaders* request_headers) { |
| 604 | observed_before_headers_sent_ = true; |
| 605 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 606 | !proxy_info.is_quic()) { |
| 607 | return; |
| 608 | } |
| 609 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 610 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 611 | } |
| 612 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 613 | bool observed_before_headers_sent_with_proxy() const { |
| 614 | return observed_before_headers_sent_with_proxy_; |
| 615 | } |
| 616 | |
| 617 | bool observed_before_headers_sent() const { |
| 618 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | std::string observed_proxy_server_uri() const { |
| 622 | return observed_proxy_server_uri_; |
| 623 | } |
| 624 | |
| 625 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 626 | bool observed_before_headers_sent_with_proxy_; |
| 627 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 628 | std::string observed_proxy_server_uri_; |
| 629 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 630 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 631 | }; |
| 632 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 633 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 634 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 635 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 636 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 637 | const int sizeof_row = strlen(row); |
| 638 | const int num_rows = static_cast<int>( |
| 639 | ceil(static_cast<float>(size) / sizeof_row)); |
| 640 | const int sizeof_data = num_rows * sizeof_row; |
| 641 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 642 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 643 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 644 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 645 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 646 | } |
| 647 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 648 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 649 | uint64_t MockGetMSTime() { |
| 650 | // Tue, 23 May 2017 20:13:07 +0000 |
| 651 | return 131400439870000000; |
| 652 | } |
| 653 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 654 | // Alternative functions that eliminate randomness and dependency on the local |
| 655 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 656 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 657 | // This is set to 0xaa because the client challenge for testing in |
| 658 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 659 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 662 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 663 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 664 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 665 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 666 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 667 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 668 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 669 | explicit CaptureGroupIdTransportSocketPool( |
| 670 | const CommonConnectJobParams* common_connect_job_params) |
| 671 | : TransportClientSocketPool(0, |
| 672 | 0, |
| 673 | base::TimeDelta(), |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 674 | ProxyServer::Direct(), |
| 675 | false /* is_for_websockets */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 676 | common_connect_job_params, |
| 677 | nullptr /* ssl_config_service */) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 678 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 679 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 680 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 681 | } |
| 682 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 683 | bool socket_requested() const { return socket_requested_; } |
| 684 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 685 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 686 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 687 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 688 | const base::Optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 689 | RequestPriority priority, |
| 690 | const SocketTag& socket_tag, |
| 691 | ClientSocketPool::RespectLimits respect_limits, |
| 692 | ClientSocketHandle* handle, |
| 693 | CompletionOnceCallback callback, |
| 694 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 695 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 696 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 697 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 698 | return ERR_IO_PENDING; |
| 699 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 700 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 701 | ClientSocketHandle* handle, |
| 702 | bool cancel_connect_job) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 703 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 704 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 705 | int64_t generation) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 706 | void CloseIdleSockets() override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 707 | void CloseIdleSocketsInGroup( |
| 708 | const ClientSocketPool::GroupId& group_id) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 709 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 710 | size_t IdleSocketCountInGroup( |
| 711 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 712 | return 0; |
| 713 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 714 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 715 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 716 | return LOAD_STATE_IDLE; |
| 717 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 718 | |
| 719 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 720 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 721 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 722 | }; |
| 723 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | //----------------------------------------------------------------------------- |
| 725 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 726 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 727 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 728 | bool CheckBasicServerAuth( |
| 729 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 730 | if (!auth_challenge) |
| 731 | return false; |
| 732 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 733 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 734 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 735 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 736 | return true; |
| 737 | } |
| 738 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 739 | bool CheckBasicSecureServerAuth( |
| 740 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
| 741 | if (!auth_challenge) |
| 742 | return false; |
| 743 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 744 | EXPECT_EQ("https://www.example.org", auth_challenge->challenger.Serialize()); |
| 745 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 746 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 747 | return true; |
| 748 | } |
| 749 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 750 | bool CheckBasicProxyAuth( |
| 751 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 752 | if (!auth_challenge) |
| 753 | return false; |
| 754 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 755 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 756 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 757 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 758 | return true; |
| 759 | } |
| 760 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 761 | bool CheckBasicSecureProxyAuth( |
| 762 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 763 | if (!auth_challenge) |
| 764 | return false; |
| 765 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 766 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 767 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 768 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 769 | return true; |
| 770 | } |
| 771 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 772 | bool CheckDigestServerAuth( |
| 773 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 774 | if (!auth_challenge) |
| 775 | return false; |
| 776 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 777 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 778 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 779 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 780 | return true; |
| 781 | } |
| 782 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 783 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 784 | bool CheckNTLMServerAuth( |
| 785 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 786 | if (!auth_challenge) |
| 787 | return false; |
| 788 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 789 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 790 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 791 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 792 | return true; |
| 793 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 794 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 795 | bool CheckNTLMProxyAuth( |
| 796 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 797 | if (!auth_challenge) |
| 798 | return false; |
| 799 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 800 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 801 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 802 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 803 | return true; |
| 804 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 805 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 806 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 807 | } // namespace |
| 808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 809 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 812 | } |
| 813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 814 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 815 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 816 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 817 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 819 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 820 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 821 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 822 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 823 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 824 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 825 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 826 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 827 | |
| 828 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 832 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 833 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 834 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 835 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 836 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 837 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 838 | EXPECT_THAT(out.rv, IsOk()); |
| 839 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 840 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 841 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 842 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 843 | } |
| 844 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 845 | // Response with no status line, and a weird port. Should fail by default. |
| 846 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 847 | MockRead data_reads[] = { |
| 848 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 849 | }; |
| 850 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 851 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 853 | |
| 854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 855 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 856 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 857 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 858 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 859 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 860 | request.method = "GET"; |
| 861 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 862 | request.traffic_annotation = |
| 863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 864 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 865 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 866 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 867 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 868 | } |
| 869 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 870 | // Tests that request info can be destroyed after the headers phase is complete. |
| 871 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 873 | auto trans = |
| 874 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 875 | |
| 876 | MockRead data_reads[] = { |
| 877 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 878 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 879 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 880 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 881 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 882 | |
| 883 | TestCompletionCallback callback; |
| 884 | |
| 885 | { |
| 886 | auto request = std::make_unique<HttpRequestInfo>(); |
| 887 | request->method = "GET"; |
| 888 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 889 | request->traffic_annotation = |
| 890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 891 | |
| 892 | int rv = |
| 893 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 894 | |
| 895 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 896 | } // Let request info be destroyed. |
| 897 | |
| 898 | trans.reset(); |
| 899 | } |
| 900 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 901 | // Response with no status line, and a weird port. Option to allow weird ports |
| 902 | // enabled. |
| 903 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 904 | MockRead data_reads[] = { |
| 905 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 906 | }; |
| 907 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 908 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 909 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 910 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 911 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 912 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 913 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 914 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 915 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 916 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 917 | request.method = "GET"; |
| 918 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 919 | request.traffic_annotation = |
| 920 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 921 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 922 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 923 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 924 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 925 | |
| 926 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 927 | ASSERT_TRUE(info->headers); |
| 928 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 929 | |
| 930 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 931 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 932 | } |
| 933 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 935 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 937 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 938 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 939 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 940 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 941 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 942 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 943 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 944 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 945 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 949 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 950 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 951 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 952 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 953 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 954 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 955 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 956 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 957 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 958 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 959 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 963 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 964 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 965 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 966 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 967 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 968 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 969 | EXPECT_THAT(out.rv, IsOk()); |
| 970 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 971 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 972 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 973 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 977 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 978 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 979 | MockRead("\n"), |
| 980 | MockRead("\n"), |
| 981 | MockRead("Q"), |
| 982 | MockRead("J"), |
| 983 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 984 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 985 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 986 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 987 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 988 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 989 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 990 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 991 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 995 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 996 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 997 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 999 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1000 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1001 | EXPECT_THAT(out.rv, IsOk()); |
| 1002 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1003 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1004 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1005 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1006 | } |
| 1007 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1008 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1009 | // persistent connection. The response should still terminate since a 204 |
| 1010 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1011 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1012 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1013 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1014 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1015 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1016 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1017 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1018 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1019 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1020 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1021 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1022 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1023 | int64_t response_size = reads_size - strlen(junk); |
| 1024 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1025 | } |
| 1026 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1027 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1028 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1029 | std::string final_chunk = "0\r\n\r\n"; |
| 1030 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1031 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1032 | MockRead data_reads[] = { |
| 1033 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1034 | MockRead("5\r\nHello\r\n"), |
| 1035 | MockRead("1\r\n"), |
| 1036 | MockRead(" \r\n"), |
| 1037 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1038 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1039 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1040 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1041 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1042 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1043 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1044 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1045 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1046 | int64_t response_size = reads_size - extra_data.size(); |
| 1047 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1048 | } |
| 1049 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1050 | // Next tests deal with http://crbug.com/56344. |
| 1051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1052 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1053 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1054 | MockRead data_reads[] = { |
| 1055 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1056 | MockRead("Content-Length: 10\r\n"), |
| 1057 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1058 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1059 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1060 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1061 | } |
| 1062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1063 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1064 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1065 | MockRead data_reads[] = { |
| 1066 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1069 | MockRead("Hello"), |
| 1070 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1071 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1072 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1073 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1074 | EXPECT_EQ("Hello", out.response_data); |
| 1075 | } |
| 1076 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1077 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1078 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1079 | // More than 2 dupes. |
| 1080 | { |
| 1081 | MockRead data_reads[] = { |
| 1082 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1083 | MockRead("Content-Length: 5\r\n"), |
| 1084 | MockRead("Content-Length: 5\r\n"), |
| 1085 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1086 | MockRead("Hello"), |
| 1087 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1088 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1089 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1090 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1091 | EXPECT_EQ("Hello", out.response_data); |
| 1092 | } |
| 1093 | // HTTP/1.0 |
| 1094 | { |
| 1095 | MockRead data_reads[] = { |
| 1096 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1097 | MockRead("Content-Length: 5\r\n"), |
| 1098 | MockRead("Content-Length: 5\r\n"), |
| 1099 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1100 | MockRead("Hello"), |
| 1101 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1102 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1103 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1104 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1105 | EXPECT_EQ("Hello", out.response_data); |
| 1106 | } |
| 1107 | // 2 dupes and one mismatched. |
| 1108 | { |
| 1109 | MockRead data_reads[] = { |
| 1110 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1111 | MockRead("Content-Length: 10\r\n"), |
| 1112 | MockRead("Content-Length: 10\r\n"), |
| 1113 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1114 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1115 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1116 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1120 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1121 | MultipleContentLengthHeadersTransferEncoding) { |
| 1122 | MockRead data_reads[] = { |
| 1123 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1124 | MockRead("Content-Length: 666\r\n"), |
| 1125 | MockRead("Content-Length: 1337\r\n"), |
| 1126 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1127 | MockRead("5\r\nHello\r\n"), |
| 1128 | MockRead("1\r\n"), |
| 1129 | MockRead(" \r\n"), |
| 1130 | MockRead("5\r\nworld\r\n"), |
| 1131 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1132 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1133 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1134 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1135 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1136 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1137 | EXPECT_EQ("Hello world", out.response_data); |
| 1138 | } |
| 1139 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1140 | // Next tests deal with http://crbug.com/98895. |
| 1141 | |
| 1142 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1143 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1144 | MockRead data_reads[] = { |
| 1145 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1146 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1147 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1148 | MockRead("Hello"), |
| 1149 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1150 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1151 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1153 | EXPECT_EQ("Hello", out.response_data); |
| 1154 | } |
| 1155 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1156 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1157 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | MockRead data_reads[] = { |
| 1159 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1160 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1161 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1162 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1163 | MockRead("Hello"), |
| 1164 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1165 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1166 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1167 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1168 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1172 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1173 | MockRead data_reads[] = { |
| 1174 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1175 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1176 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1177 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1178 | MockRead("Hello"), |
| 1179 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1180 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1181 | EXPECT_THAT(out.rv, |
| 1182 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | } |
| 1184 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1185 | // Checks that two identical Location headers result in no error. |
| 1186 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1187 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | MockRead data_reads[] = { |
| 1189 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1190 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1191 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1193 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | }; |
| 1195 | |
| 1196 | HttpRequestInfo request; |
| 1197 | request.method = "GET"; |
| 1198 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1199 | request.traffic_annotation = |
| 1200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1203 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1204 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1205 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1206 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1208 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1209 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1210 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1212 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1213 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1215 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1216 | ASSERT_TRUE(response); |
| 1217 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1218 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1219 | std::string url; |
| 1220 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1221 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1222 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1223 | } |
| 1224 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1225 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1226 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1227 | MockRead data_reads[] = { |
| 1228 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1229 | MockRead("Location: http://good.com/\r\n"), |
| 1230 | MockRead("Location: http://evil.com/\r\n"), |
| 1231 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1232 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1233 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1234 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1235 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1236 | } |
| 1237 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1238 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1239 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1240 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1241 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1242 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1243 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1244 | request.traffic_annotation = |
| 1245 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1248 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1249 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1250 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1251 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1252 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1253 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1255 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1256 | "Host: www.example.org\r\n" |
| 1257 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | }; |
| 1259 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1260 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1261 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1263 | // No response body because the test stops reading here. |
| 1264 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1265 | }; |
| 1266 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1267 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1268 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1270 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1271 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1272 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1274 | |
| 1275 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1278 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1279 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1280 | |
| 1281 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1282 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1283 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1284 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1285 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1286 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1287 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1288 | |
| 1289 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1290 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1291 | bool has_server_header = response->headers->EnumerateHeader( |
| 1292 | &iter, "Server", &server_header); |
| 1293 | EXPECT_TRUE(has_server_header); |
| 1294 | EXPECT_EQ("Blah", server_header); |
| 1295 | |
| 1296 | // Reading should give EOF right away, since there is no message body |
| 1297 | // (despite non-zero content-length). |
| 1298 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1299 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1301 | EXPECT_EQ("", response_data); |
| 1302 | } |
| 1303 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1304 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
| 1307 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1308 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1309 | MockRead("hello"), |
| 1310 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1311 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1312 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1314 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1315 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1317 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | "hello", "world" |
| 1319 | }; |
| 1320 | |
| 1321 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1322 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1324 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 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 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1330 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1332 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | |
| 1335 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1336 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1338 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1339 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1340 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1341 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1342 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1343 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
| 1345 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1346 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1347 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1348 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1352 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1353 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1354 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1355 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1356 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1357 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1358 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | request.method = "POST"; |
| 1360 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1361 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1362 | request.traffic_annotation = |
| 1363 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1365 | // Check the upload progress returned before initialization is correct. |
| 1366 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1367 | EXPECT_EQ(0u, progress.size()); |
| 1368 | EXPECT_EQ(0u, progress.position()); |
| 1369 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1371 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1372 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1373 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1374 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1375 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1376 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1377 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1379 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1380 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1382 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1384 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1386 | |
| 1387 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1388 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1390 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1391 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1392 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1393 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1394 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1395 | |
| 1396 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1397 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1398 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1399 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1400 | } |
| 1401 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | // This test is almost the same as Ignores100 above, but the response contains |
| 1403 | // 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] | 1404 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1405 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1406 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1407 | request.method = "GET"; |
| 1408 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1409 | request.traffic_annotation = |
| 1410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1414 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1415 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1416 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1417 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1418 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1419 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1420 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1421 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1424 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1425 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1426 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1428 | |
| 1429 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1430 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1432 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1433 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1434 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1435 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1436 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1437 | |
| 1438 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1439 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1441 | EXPECT_EQ("hello world", response_data); |
| 1442 | } |
| 1443 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1444 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1445 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1446 | base::TimeDelta::FromMilliseconds(10); |
| 1447 | |
| 1448 | HttpRequestInfo request; |
| 1449 | request.method = "GET"; |
| 1450 | request.url = GURL("http://www.foo.com/"); |
| 1451 | request.traffic_annotation = |
| 1452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1453 | |
| 1454 | std::vector<MockWrite> data_writes = { |
| 1455 | MockWrite(ASYNC, 0, |
| 1456 | "GET / HTTP/1.1\r\n" |
| 1457 | "Host: www.foo.com\r\n" |
| 1458 | "Connection: keep-alive\r\n\r\n"), |
| 1459 | }; |
| 1460 | |
| 1461 | std::vector<MockRead> data_reads = { |
| 1462 | // Write one byte of the status line, followed by a pause. |
| 1463 | MockRead(ASYNC, 1, "H"), |
| 1464 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1465 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1466 | MockRead(ASYNC, 4, "hello world"), |
| 1467 | MockRead(SYNCHRONOUS, OK, 5), |
| 1468 | }; |
| 1469 | |
| 1470 | SequencedSocketData data(data_reads, data_writes); |
| 1471 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1472 | |
| 1473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1474 | |
| 1475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1476 | |
| 1477 | TestCompletionCallback callback; |
| 1478 | |
| 1479 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1481 | |
| 1482 | data.RunUntilPaused(); |
| 1483 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1484 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1485 | data.Resume(); |
| 1486 | |
| 1487 | rv = callback.WaitForResult(); |
| 1488 | EXPECT_THAT(rv, IsOk()); |
| 1489 | |
| 1490 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1491 | ASSERT_TRUE(response); |
| 1492 | |
| 1493 | EXPECT_TRUE(response->headers); |
| 1494 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1495 | |
| 1496 | LoadTimingInfo load_timing_info; |
| 1497 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1498 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1499 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1500 | // Ensure we didn't include the delay in the TTFB time. |
| 1501 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1502 | load_timing_info.connect_timing.connect_end); |
| 1503 | // Ensure that the mock clock advanced at all. |
| 1504 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1505 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1506 | |
| 1507 | std::string response_data; |
| 1508 | rv = ReadTransaction(&trans, &response_data); |
| 1509 | EXPECT_THAT(rv, IsOk()); |
| 1510 | EXPECT_EQ("hello world", response_data); |
| 1511 | } |
| 1512 | |
| 1513 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1514 | // info uses the first response, even if 1XX/informational. |
| 1515 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1516 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1517 | base::TimeDelta::FromMilliseconds(10); |
| 1518 | |
| 1519 | HttpRequestInfo request; |
| 1520 | request.method = "GET"; |
| 1521 | request.url = GURL("https://www.foo.com/"); |
| 1522 | request.traffic_annotation = |
| 1523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1524 | |
| 1525 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1527 | |
| 1528 | std::vector<MockWrite> data_writes; |
| 1529 | std::vector<MockRead> data_reads; |
| 1530 | |
| 1531 | spdy::SpdySerializedFrame spdy_req( |
| 1532 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1533 | |
| 1534 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1535 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1536 | spdy::SpdySerializedFrame spdy_resp1( |
| 1537 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1538 | spdy::SpdySerializedFrame spdy_resp2( |
| 1539 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1540 | spdy::SpdySerializedFrame spdy_data( |
| 1541 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1542 | |
| 1543 | if (use_spdy) { |
| 1544 | ssl.next_proto = kProtoHTTP2; |
| 1545 | |
| 1546 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1547 | |
| 1548 | data_reads = { |
| 1549 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1550 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1551 | MockRead(SYNCHRONOUS, OK, 5), |
| 1552 | }; |
| 1553 | } else { |
| 1554 | data_writes = { |
| 1555 | MockWrite(ASYNC, 0, |
| 1556 | "GET / HTTP/1.1\r\n" |
| 1557 | "Host: www.foo.com\r\n" |
| 1558 | "Connection: keep-alive\r\n\r\n"), |
| 1559 | }; |
| 1560 | |
| 1561 | data_reads = { |
| 1562 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1563 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1564 | |
| 1565 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1566 | MockRead(ASYNC, 4, "hello world"), |
| 1567 | MockRead(SYNCHRONOUS, OK, 5), |
| 1568 | }; |
| 1569 | } |
| 1570 | |
| 1571 | SequencedSocketData data(data_reads, data_writes); |
| 1572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1573 | |
| 1574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1575 | |
| 1576 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1577 | |
| 1578 | TestCompletionCallback callback; |
| 1579 | |
| 1580 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1582 | |
| 1583 | data.RunUntilPaused(); |
| 1584 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1585 | // the delay before parsing the 200 response. |
| 1586 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1587 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1588 | data.Resume(); |
| 1589 | |
| 1590 | rv = callback.WaitForResult(); |
| 1591 | EXPECT_THAT(rv, IsOk()); |
| 1592 | |
| 1593 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1594 | ASSERT_TRUE(response); |
| 1595 | |
| 1596 | LoadTimingInfo load_timing_info; |
| 1597 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1598 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1599 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1600 | // Ensure we didn't include the delay in the TTFB time. |
| 1601 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1602 | load_timing_info.connect_timing.connect_end); |
| 1603 | // Ensure that the mock clock advanced at all. |
| 1604 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1605 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1606 | |
| 1607 | std::string response_data; |
| 1608 | rv = ReadTransaction(&trans, &response_data); |
| 1609 | EXPECT_THAT(rv, IsOk()); |
| 1610 | EXPECT_EQ("hello world", response_data); |
| 1611 | } |
| 1612 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1613 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1614 | Check100ResponseTiming(false /* use_spdy */); |
| 1615 | } |
| 1616 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1617 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1618 | Check100ResponseTiming(true /* use_spdy */); |
| 1619 | } |
| 1620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1621 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1622 | HttpRequestInfo request; |
| 1623 | request.method = "POST"; |
| 1624 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1625 | request.traffic_annotation = |
| 1626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1629 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1630 | |
| 1631 | MockRead data_reads[] = { |
| 1632 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1633 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1634 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1635 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1636 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1637 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1638 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1642 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1645 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1646 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1647 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1648 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1649 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1650 | } |
| 1651 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1652 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1653 | HttpRequestInfo request; |
| 1654 | request.method = "POST"; |
| 1655 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1656 | request.traffic_annotation = |
| 1657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1661 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1662 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1663 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1664 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1665 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1668 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1670 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1672 | |
| 1673 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1674 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1675 | } |
| 1676 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1677 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1678 | const MockWrite* write_failure, |
| 1679 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1680 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1681 | request.method = "GET"; |
| 1682 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1683 | request.traffic_annotation = |
| 1684 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1685 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1686 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1687 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1689 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1690 | // Written data for successfully sending both requests. |
| 1691 | MockWrite data1_writes[] = { |
| 1692 | MockWrite("GET / HTTP/1.1\r\n" |
| 1693 | "Host: www.foo.com\r\n" |
| 1694 | "Connection: keep-alive\r\n\r\n"), |
| 1695 | MockWrite("GET / HTTP/1.1\r\n" |
| 1696 | "Host: www.foo.com\r\n" |
| 1697 | "Connection: keep-alive\r\n\r\n") |
| 1698 | }; |
| 1699 | |
| 1700 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1701 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1702 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1703 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1704 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1706 | |
| 1707 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1708 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1709 | data1_writes[1] = *write_failure; |
| 1710 | } else { |
| 1711 | ASSERT_TRUE(read_failure); |
| 1712 | data1_reads[2] = *read_failure; |
| 1713 | } |
| 1714 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1715 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1716 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1717 | |
| 1718 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1719 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1720 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1721 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1722 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1723 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1724 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1725 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1726 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1727 | "hello", "world" |
| 1728 | }; |
| 1729 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1730 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1731 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1732 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1734 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1736 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1738 | |
| 1739 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1740 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1741 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1742 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1743 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1744 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1745 | if (i == 0) { |
| 1746 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1747 | } else { |
| 1748 | // The second request should be using a new socket. |
| 1749 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1750 | } |
| 1751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1752 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1753 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1754 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1755 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1756 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1757 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1758 | |
| 1759 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1760 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1761 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1762 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1763 | } |
| 1764 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1765 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1766 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1767 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1768 | const MockRead* read_failure, |
| 1769 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1770 | HttpRequestInfo request; |
| 1771 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1772 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1773 | request.traffic_annotation = |
| 1774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1775 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1776 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1777 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1778 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1779 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1780 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1781 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1782 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1783 | ssl1.next_proto = kProtoHTTP2; |
| 1784 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1785 | } |
| 1786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1788 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1789 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1790 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1791 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1792 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1793 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1794 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1795 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1796 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1797 | // HTTP/1.1 versions of the request and response. |
| 1798 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1799 | "Host: www.foo.com\r\n" |
| 1800 | "Connection: keep-alive\r\n\r\n"; |
| 1801 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1802 | const char kHttpData[] = "hello"; |
| 1803 | |
| 1804 | std::vector<MockRead> data1_reads; |
| 1805 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1806 | if (write_failure) { |
| 1807 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1808 | data1_writes.push_back(*write_failure); |
| 1809 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1810 | } else { |
| 1811 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1812 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1813 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1814 | } else { |
| 1815 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1816 | } |
| 1817 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1818 | } |
| 1819 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1820 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1821 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1822 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1823 | std::vector<MockRead> data2_reads; |
| 1824 | std::vector<MockWrite> data2_writes; |
| 1825 | |
| 1826 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1827 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1828 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1829 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1830 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1831 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1832 | } else { |
| 1833 | data2_writes.push_back( |
| 1834 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1835 | |
| 1836 | data2_reads.push_back( |
| 1837 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1838 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1839 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1840 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1841 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1842 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1843 | |
| 1844 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1845 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1846 | // Wait for the preconnect to complete. |
| 1847 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1848 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1849 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1850 | |
| 1851 | // Make the request. |
| 1852 | TestCompletionCallback callback; |
| 1853 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1858 | |
| 1859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1861 | |
| 1862 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1863 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1864 | TestLoadTimingNotReused( |
| 1865 | load_timing_info, |
| 1866 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1868 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1869 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1870 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1871 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1872 | if (response->was_fetched_via_spdy) { |
| 1873 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1874 | } else { |
| 1875 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1876 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1877 | |
| 1878 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1879 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1880 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1881 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1882 | } |
| 1883 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1884 | // Test that we do not retry indefinitely when a server sends an error like |
| 1885 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1886 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1887 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1888 | HttpRequestInfo request; |
| 1889 | request.method = "GET"; |
| 1890 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1891 | request.traffic_annotation = |
| 1892 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1893 | |
| 1894 | // Check whether we give up after the third try. |
| 1895 | |
| 1896 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1897 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1898 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1899 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1900 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1901 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1902 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1903 | |
| 1904 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1905 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1906 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1907 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1908 | |
| 1909 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1910 | AddSSLSocketData(); |
| 1911 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1912 | AddSSLSocketData(); |
| 1913 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1914 | AddSSLSocketData(); |
| 1915 | |
| 1916 | TestCompletionCallback callback; |
| 1917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1919 | |
| 1920 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1922 | |
| 1923 | rv = callback.WaitForResult(); |
| 1924 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1925 | } |
| 1926 | |
| 1927 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1928 | HttpRequestInfo request; |
| 1929 | request.method = "GET"; |
| 1930 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1931 | request.traffic_annotation = |
| 1932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1933 | |
| 1934 | // Check whether we try atleast thrice before giving up. |
| 1935 | |
| 1936 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1937 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1938 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1939 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1940 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1941 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1942 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1943 | |
| 1944 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1945 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1946 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1947 | spdy::SpdySerializedFrame spdy_data( |
| 1948 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1949 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1950 | CreateMockRead(spdy_data, 2)}; |
| 1951 | |
| 1952 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1953 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1954 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1955 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1956 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1957 | |
| 1958 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1959 | AddSSLSocketData(); |
| 1960 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1961 | AddSSLSocketData(); |
| 1962 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1963 | AddSSLSocketData(); |
| 1964 | |
| 1965 | TestCompletionCallback callback; |
| 1966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1968 | |
| 1969 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1971 | |
| 1972 | rv = callback.WaitForResult(); |
| 1973 | EXPECT_THAT(rv, IsOk()); |
| 1974 | } |
| 1975 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1976 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1977 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1978 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1979 | } |
| 1980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1981 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1982 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1983 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1984 | } |
| 1985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1986 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1987 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1988 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1989 | } |
| 1990 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1991 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1992 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1993 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1994 | MockRead read_failure(SYNCHRONOUS, |
| 1995 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1996 | "Connection: Keep-Alive\r\n" |
| 1997 | "Content-Length: 6\r\n\r\n" |
| 1998 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1999 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2000 | } |
| 2001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2002 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2003 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2004 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2005 | } |
| 2006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2007 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2008 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2009 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2010 | } |
| 2011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2012 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2013 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2014 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2015 | } |
| 2016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2017 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2018 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2019 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2020 | } |
| 2021 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2022 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2023 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2024 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2025 | MockRead read_failure(SYNCHRONOUS, |
| 2026 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2027 | "Connection: Keep-Alive\r\n" |
| 2028 | "Content-Length: 6\r\n\r\n" |
| 2029 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2030 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2031 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2032 | } |
| 2033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2034 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2035 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2036 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2037 | } |
| 2038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2039 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2040 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2041 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2042 | } |
| 2043 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2044 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2045 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2046 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2047 | } |
| 2048 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2049 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2050 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2051 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2052 | } |
| 2053 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2054 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2055 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2056 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2057 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2058 | request.traffic_annotation = |
| 2059 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2062 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2063 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2064 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2065 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2066 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2067 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2068 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2069 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2070 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2073 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2075 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2077 | |
| 2078 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2079 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2080 | |
| 2081 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2082 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2083 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | // What do various browsers do when the server closes a non-keepalive |
| 2087 | // connection without sending any response header or body? |
| 2088 | // |
| 2089 | // IE7: error page |
| 2090 | // Safari 3.1.2 (Windows): error page |
| 2091 | // Firefox 3.0.1: blank page |
| 2092 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2093 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2094 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2095 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2096 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2097 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2098 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2099 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2101 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2102 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2103 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2104 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2105 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2106 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2107 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2108 | // destructor in such situations. |
| 2109 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2110 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2111 | HttpRequestInfo request; |
| 2112 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2113 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2114 | request.traffic_annotation = |
| 2115 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2116 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2118 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2119 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2120 | |
| 2121 | MockRead data_reads[] = { |
| 2122 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2123 | MockRead("Connection: keep-alive\r\n"), |
| 2124 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2125 | MockRead("hello"), |
| 2126 | MockRead(SYNCHRONOUS, 0), |
| 2127 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2128 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2129 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2130 | |
| 2131 | TestCompletionCallback callback; |
| 2132 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2133 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2135 | |
| 2136 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2137 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2138 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2139 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2140 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2141 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2142 | if (rv == ERR_IO_PENDING) |
| 2143 | rv = callback.WaitForResult(); |
| 2144 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2145 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2146 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2147 | |
| 2148 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2149 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2150 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2151 | } |
| 2152 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2153 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2154 | HttpRequestInfo request; |
| 2155 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2156 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2157 | request.traffic_annotation = |
| 2158 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2159 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2160 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2161 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2162 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2163 | |
| 2164 | MockRead data_reads[] = { |
| 2165 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2166 | MockRead("Connection: keep-alive\r\n"), |
| 2167 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2168 | MockRead(SYNCHRONOUS, 0), |
| 2169 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2170 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2171 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2172 | |
| 2173 | TestCompletionCallback callback; |
| 2174 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2175 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2177 | |
| 2178 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2180 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2181 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2182 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2183 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2184 | if (rv == ERR_IO_PENDING) |
| 2185 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2186 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2187 | |
| 2188 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2189 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2190 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2191 | } |
| 2192 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2193 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2194 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2195 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2196 | HttpRequestInfo request; |
| 2197 | request.method = "GET"; |
| 2198 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2199 | request.traffic_annotation = |
| 2200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2201 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2202 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2203 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2204 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2205 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2206 | const char* request_data = |
| 2207 | "GET / HTTP/1.1\r\n" |
| 2208 | "Host: www.foo.com\r\n" |
| 2209 | "Connection: keep-alive\r\n\r\n"; |
| 2210 | MockWrite data_writes[] = { |
| 2211 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2212 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2213 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2214 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2215 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2216 | }; |
| 2217 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2218 | // Note that because all these reads happen in the same |
| 2219 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2220 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2221 | MockRead data_reads[] = { |
| 2222 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2223 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2224 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2225 | MockRead(ASYNC, 7, |
| 2226 | "HTTP/1.1 302 Found\r\n" |
| 2227 | "Content-Length: 0\r\n\r\n"), |
| 2228 | MockRead(ASYNC, 9, |
| 2229 | "HTTP/1.1 302 Found\r\n" |
| 2230 | "Content-Length: 5\r\n\r\n" |
| 2231 | "hello"), |
| 2232 | MockRead(ASYNC, 11, |
| 2233 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2234 | "Content-Length: 0\r\n\r\n"), |
| 2235 | MockRead(ASYNC, 13, |
| 2236 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2237 | "Content-Length: 5\r\n\r\n" |
| 2238 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2239 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2240 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2241 | // the set_busy_before_sync_reads(true) call, while the |
| 2242 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2243 | // reuseable. See http://crbug.com/544255. |
| 2244 | MockRead(ASYNC, 15, |
| 2245 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2246 | "Content-Length: 5\r\n\r\n"), |
| 2247 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2248 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2249 | MockRead(ASYNC, 18, |
| 2250 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2251 | "Content-Length: 5\r\n\r\n" |
| 2252 | "he"), |
| 2253 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2254 | |
| 2255 | // The body of the final request is actually read. |
| 2256 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2257 | MockRead(ASYNC, 22, "hello"), |
| 2258 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2259 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2260 | data.set_busy_before_sync_reads(true); |
| 2261 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2262 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2263 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2264 | std::string response_lines[kNumUnreadBodies]; |
| 2265 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2266 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2267 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2268 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2269 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2270 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2271 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2272 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2273 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2274 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2275 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2276 | LoadTimingInfo load_timing_info; |
| 2277 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2278 | if (i == 0) { |
| 2279 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2280 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2281 | } else { |
| 2282 | TestLoadTimingReused(load_timing_info); |
| 2283 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2284 | } |
| 2285 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2286 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2287 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2288 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2289 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2290 | response_lines[i] = response->headers->GetStatusLine(); |
| 2291 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2292 | // Delete the transaction without reading the response bodies. Then spin |
| 2293 | // the message loop, so the response bodies are drained. |
| 2294 | trans.reset(); |
| 2295 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2296 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2297 | |
| 2298 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2299 | "HTTP/1.1 204 No Content", |
| 2300 | "HTTP/1.1 205 Reset Content", |
| 2301 | "HTTP/1.1 304 Not Modified", |
| 2302 | "HTTP/1.1 302 Found", |
| 2303 | "HTTP/1.1 302 Found", |
| 2304 | "HTTP/1.1 301 Moved Permanently", |
| 2305 | "HTTP/1.1 301 Moved Permanently", |
| 2306 | "HTTP/1.1 200 Hunky-Dory", |
| 2307 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2308 | }; |
| 2309 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2310 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2311 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2312 | |
| 2313 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2314 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2316 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2317 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2318 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2319 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2320 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2321 | ASSERT_TRUE(response); |
| 2322 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2323 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2324 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2325 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2326 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2327 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2328 | } |
| 2329 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2330 | // Sockets that receive extra data after a response is complete should not be |
| 2331 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2332 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2334 | MockWrite data_writes1[] = { |
| 2335 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2336 | "Host: www.borked.com\r\n" |
| 2337 | "Connection: keep-alive\r\n\r\n"), |
| 2338 | }; |
| 2339 | |
| 2340 | MockRead data_reads1[] = { |
| 2341 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2342 | "Connection: keep-alive\r\n" |
| 2343 | "Content-Length: 22\r\n\r\n" |
| 2344 | "This server is borked."), |
| 2345 | }; |
| 2346 | |
| 2347 | MockWrite data_writes2[] = { |
| 2348 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2349 | "Host: www.borked.com\r\n" |
| 2350 | "Connection: keep-alive\r\n\r\n"), |
| 2351 | }; |
| 2352 | |
| 2353 | MockRead data_reads2[] = { |
| 2354 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2355 | "Content-Length: 3\r\n\r\n" |
| 2356 | "foo"), |
| 2357 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2358 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2359 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2360 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2361 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2362 | |
| 2363 | TestCompletionCallback callback; |
| 2364 | HttpRequestInfo request1; |
| 2365 | request1.method = "HEAD"; |
| 2366 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2367 | request1.traffic_annotation = |
| 2368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2369 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2370 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2371 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2372 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2373 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2374 | |
| 2375 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2376 | ASSERT_TRUE(response1); |
| 2377 | ASSERT_TRUE(response1->headers); |
| 2378 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2379 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2380 | |
| 2381 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2382 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2383 | EXPECT_EQ("", response_data1); |
| 2384 | // Deleting the transaction attempts to release the socket back into the |
| 2385 | // socket pool. |
| 2386 | trans1.reset(); |
| 2387 | |
| 2388 | HttpRequestInfo request2; |
| 2389 | request2.method = "GET"; |
| 2390 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2391 | request2.traffic_annotation = |
| 2392 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2393 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2394 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2395 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2396 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2397 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2398 | |
| 2399 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2400 | ASSERT_TRUE(response2); |
| 2401 | ASSERT_TRUE(response2->headers); |
| 2402 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2403 | |
| 2404 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2405 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2406 | EXPECT_EQ("foo", response_data2); |
| 2407 | } |
| 2408 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2409 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2411 | MockWrite data_writes1[] = { |
| 2412 | MockWrite("GET / HTTP/1.1\r\n" |
| 2413 | "Host: www.borked.com\r\n" |
| 2414 | "Connection: keep-alive\r\n\r\n"), |
| 2415 | }; |
| 2416 | |
| 2417 | MockRead data_reads1[] = { |
| 2418 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2419 | "Connection: keep-alive\r\n" |
| 2420 | "Content-Length: 22\r\n\r\n" |
| 2421 | "This server is borked." |
| 2422 | "Bonus data!"), |
| 2423 | }; |
| 2424 | |
| 2425 | MockWrite data_writes2[] = { |
| 2426 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2427 | "Host: www.borked.com\r\n" |
| 2428 | "Connection: keep-alive\r\n\r\n"), |
| 2429 | }; |
| 2430 | |
| 2431 | MockRead data_reads2[] = { |
| 2432 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2433 | "Content-Length: 3\r\n\r\n" |
| 2434 | "foo"), |
| 2435 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2436 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2437 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2438 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2439 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2440 | |
| 2441 | TestCompletionCallback callback; |
| 2442 | HttpRequestInfo request1; |
| 2443 | request1.method = "GET"; |
| 2444 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2445 | request1.traffic_annotation = |
| 2446 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2447 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2448 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2449 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2450 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2451 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2452 | |
| 2453 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2454 | ASSERT_TRUE(response1); |
| 2455 | ASSERT_TRUE(response1->headers); |
| 2456 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2457 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2458 | |
| 2459 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2460 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2461 | EXPECT_EQ("This server is borked.", response_data1); |
| 2462 | // Deleting the transaction attempts to release the socket back into the |
| 2463 | // socket pool. |
| 2464 | trans1.reset(); |
| 2465 | |
| 2466 | HttpRequestInfo request2; |
| 2467 | request2.method = "GET"; |
| 2468 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2469 | request2.traffic_annotation = |
| 2470 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2471 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2472 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2473 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2474 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2475 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2476 | |
| 2477 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2478 | ASSERT_TRUE(response2); |
| 2479 | ASSERT_TRUE(response2->headers); |
| 2480 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2481 | |
| 2482 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2483 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2484 | EXPECT_EQ("foo", response_data2); |
| 2485 | } |
| 2486 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2487 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2489 | MockWrite data_writes1[] = { |
| 2490 | MockWrite("GET / HTTP/1.1\r\n" |
| 2491 | "Host: www.borked.com\r\n" |
| 2492 | "Connection: keep-alive\r\n\r\n"), |
| 2493 | }; |
| 2494 | |
| 2495 | MockRead data_reads1[] = { |
| 2496 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2497 | "Connection: keep-alive\r\n" |
| 2498 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2499 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2500 | MockRead("0\r\n\r\nBonus data!"), |
| 2501 | }; |
| 2502 | |
| 2503 | MockWrite data_writes2[] = { |
| 2504 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2505 | "Host: www.borked.com\r\n" |
| 2506 | "Connection: keep-alive\r\n\r\n"), |
| 2507 | }; |
| 2508 | |
| 2509 | MockRead data_reads2[] = { |
| 2510 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2511 | "Content-Length: 3\r\n\r\n" |
| 2512 | "foo"), |
| 2513 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2514 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2516 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2517 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2518 | |
| 2519 | TestCompletionCallback callback; |
| 2520 | HttpRequestInfo request1; |
| 2521 | request1.method = "GET"; |
| 2522 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2523 | request1.traffic_annotation = |
| 2524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2525 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2526 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2527 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2528 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2529 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2530 | |
| 2531 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2532 | ASSERT_TRUE(response1); |
| 2533 | ASSERT_TRUE(response1->headers); |
| 2534 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2535 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2536 | |
| 2537 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2538 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2539 | EXPECT_EQ("This server is borked.", response_data1); |
| 2540 | // Deleting the transaction attempts to release the socket back into the |
| 2541 | // socket pool. |
| 2542 | trans1.reset(); |
| 2543 | |
| 2544 | HttpRequestInfo request2; |
| 2545 | request2.method = "GET"; |
| 2546 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2547 | request2.traffic_annotation = |
| 2548 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2549 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2550 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2551 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2552 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2553 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2554 | |
| 2555 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2556 | ASSERT_TRUE(response2); |
| 2557 | ASSERT_TRUE(response2->headers); |
| 2558 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2559 | |
| 2560 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2561 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2562 | EXPECT_EQ("foo", response_data2); |
| 2563 | } |
| 2564 | |
| 2565 | // This is a little different from the others - it tests the case that the |
| 2566 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2567 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2568 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2569 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2570 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2571 | MockWrite data_writes1[] = { |
| 2572 | MockWrite("GET / HTTP/1.1\r\n" |
| 2573 | "Host: www.borked.com\r\n" |
| 2574 | "Connection: keep-alive\r\n\r\n"), |
| 2575 | }; |
| 2576 | |
| 2577 | MockRead data_reads1[] = { |
| 2578 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2579 | "Connection: keep-alive\r\n" |
| 2580 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2581 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2582 | MockRead("0\r\n\r\nBonus data!"), |
| 2583 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2584 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2585 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2586 | |
| 2587 | TestCompletionCallback callback; |
| 2588 | HttpRequestInfo request1; |
| 2589 | request1.method = "GET"; |
| 2590 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2591 | request1.traffic_annotation = |
| 2592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2593 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2594 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2595 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2596 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2597 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2598 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2599 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2600 | ASSERT_TRUE(response1); |
| 2601 | ASSERT_TRUE(response1->headers); |
| 2602 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2603 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2604 | |
| 2605 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2606 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2607 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2608 | |
| 2609 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2610 | // socket can't be reused, rather than returning it to the socket pool. |
| 2611 | base::RunLoop().RunUntilIdle(); |
| 2612 | |
| 2613 | // There should be no idle sockets in the pool. |
| 2614 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2615 | } |
| 2616 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2617 | // Test the request-challenge-retry sequence for basic auth. |
| 2618 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2619 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2620 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2622 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2623 | request.traffic_annotation = |
| 2624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2625 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2626 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2627 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2629 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2630 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2631 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2632 | MockWrite( |
| 2633 | "GET / HTTP/1.1\r\n" |
| 2634 | "Host: www.example.org\r\n" |
| 2635 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2636 | }; |
| 2637 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2638 | MockRead data_reads1[] = { |
| 2639 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2640 | // Give a couple authenticate options (only the middle one is actually |
| 2641 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2642 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2643 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2644 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2645 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2646 | // Large content-length -- won't matter, as connection will be reset. |
| 2647 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2648 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2649 | }; |
| 2650 | |
| 2651 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2652 | // be issuing -- the final header line contains the credentials. |
| 2653 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2654 | MockWrite( |
| 2655 | "GET / HTTP/1.1\r\n" |
| 2656 | "Host: www.example.org\r\n" |
| 2657 | "Connection: keep-alive\r\n" |
| 2658 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2659 | }; |
| 2660 | |
| 2661 | // Lastly, the server responds with the actual content. |
| 2662 | MockRead data_reads2[] = { |
| 2663 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2665 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2667 | }; |
| 2668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2669 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2670 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2671 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2672 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2673 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2674 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2676 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2678 | |
| 2679 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2680 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2681 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2682 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2683 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2684 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2685 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2686 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2687 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2688 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2689 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2691 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2692 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2693 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2694 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2695 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2697 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2699 | |
| 2700 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2702 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2703 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2704 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2705 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2706 | // The load timing after restart should have a new socket ID, and times after |
| 2707 | // those of the first load timing. |
| 2708 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2709 | load_timing_info2.connect_timing.connect_start); |
| 2710 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2711 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2712 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2713 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2714 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2715 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2717 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2718 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2719 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2720 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2721 | } |
| 2722 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2723 | // Test the request-challenge-retry sequence for basic auth. |
| 2724 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2725 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2726 | HttpRequestInfo request; |
| 2727 | request.method = "GET"; |
| 2728 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2729 | request.traffic_annotation = |
| 2730 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2731 | |
| 2732 | TestNetLog log; |
| 2733 | MockHostResolver* resolver = new MockHostResolver(); |
| 2734 | session_deps_.net_log = &log; |
| 2735 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2736 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2738 | |
| 2739 | resolver->rules()->ClearRules(); |
| 2740 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2741 | |
| 2742 | MockWrite data_writes1[] = { |
| 2743 | MockWrite("GET / HTTP/1.1\r\n" |
| 2744 | "Host: www.example.org\r\n" |
| 2745 | "Connection: keep-alive\r\n\r\n"), |
| 2746 | }; |
| 2747 | |
| 2748 | MockRead data_reads1[] = { |
| 2749 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2750 | // Give a couple authenticate options (only the middle one is actually |
| 2751 | // supported). |
| 2752 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2753 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2754 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2755 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2756 | // Large content-length -- won't matter, as connection will be reset. |
| 2757 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2758 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2759 | }; |
| 2760 | |
| 2761 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2762 | // be issuing -- the final header line contains the credentials. |
| 2763 | MockWrite data_writes2[] = { |
| 2764 | MockWrite("GET / HTTP/1.1\r\n" |
| 2765 | "Host: www.example.org\r\n" |
| 2766 | "Connection: keep-alive\r\n" |
| 2767 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2768 | }; |
| 2769 | |
| 2770 | // Lastly, the server responds with the actual content. |
| 2771 | MockRead data_reads2[] = { |
| 2772 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2773 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2774 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2775 | }; |
| 2776 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2777 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2778 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2779 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2780 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2781 | |
| 2782 | TestCompletionCallback callback1; |
| 2783 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2785 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2786 | |
| 2787 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2789 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2790 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2791 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2792 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2793 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2794 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2796 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2797 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2798 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2799 | |
| 2800 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2801 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2802 | ASSERT_FALSE(endpoint.address().empty()); |
| 2803 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2804 | |
| 2805 | resolver->rules()->ClearRules(); |
| 2806 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2807 | |
| 2808 | TestCompletionCallback callback2; |
| 2809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2810 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2811 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2812 | |
| 2813 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2814 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2815 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2816 | // The load timing after restart should have a new socket ID, and times after |
| 2817 | // those of the first load timing. |
| 2818 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2819 | load_timing_info2.connect_timing.connect_start); |
| 2820 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2821 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2822 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2823 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2824 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2825 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2827 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2828 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2829 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2830 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2832 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2833 | ASSERT_FALSE(endpoint.address().empty()); |
| 2834 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2835 | } |
| 2836 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2837 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2838 | // will eventually give up. |
| 2839 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2840 | HttpRequestInfo request; |
| 2841 | request.method = "GET"; |
| 2842 | request.url = GURL("http://www.example.org/"); |
| 2843 | request.traffic_annotation = |
| 2844 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2845 | |
| 2846 | TestNetLog log; |
| 2847 | session_deps_.net_log = &log; |
| 2848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2849 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2850 | |
| 2851 | MockWrite data_writes[] = { |
| 2852 | MockWrite("GET / HTTP/1.1\r\n" |
| 2853 | "Host: www.example.org\r\n" |
| 2854 | "Connection: keep-alive\r\n\r\n"), |
| 2855 | }; |
| 2856 | |
| 2857 | MockRead data_reads[] = { |
| 2858 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2859 | // Give a couple authenticate options (only the middle one is actually |
| 2860 | // supported). |
| 2861 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2862 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2863 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2864 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2865 | // Large content-length -- won't matter, as connection will be reset. |
| 2866 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2867 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2868 | }; |
| 2869 | |
| 2870 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2871 | // be issuing -- the final header line contains the credentials. |
| 2872 | MockWrite data_writes_restart[] = { |
| 2873 | MockWrite("GET / HTTP/1.1\r\n" |
| 2874 | "Host: www.example.org\r\n" |
| 2875 | "Connection: keep-alive\r\n" |
| 2876 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2877 | }; |
| 2878 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2879 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2881 | |
| 2882 | TestCompletionCallback callback; |
| 2883 | int rv = callback.GetResult( |
| 2884 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2885 | |
| 2886 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2887 | for (int i = 0; i < 32; i++) { |
| 2888 | // Check the previous response was a 401. |
| 2889 | EXPECT_THAT(rv, IsOk()); |
| 2890 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2891 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2892 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2893 | |
| 2894 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2895 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2896 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2897 | data_restarts.back().get()); |
| 2898 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2899 | callback.callback())); |
| 2900 | } |
| 2901 | |
| 2902 | // After too many tries, the transaction should have given up. |
| 2903 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2904 | } |
| 2905 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2906 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2907 | HttpRequestInfo request; |
| 2908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2909 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2910 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2911 | request.traffic_annotation = |
| 2912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2913 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2916 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2917 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2918 | MockWrite( |
| 2919 | "GET / HTTP/1.1\r\n" |
| 2920 | "Host: www.example.org\r\n" |
| 2921 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2922 | }; |
| 2923 | |
| 2924 | MockRead data_reads[] = { |
| 2925 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2926 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2927 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2928 | // Large content-length -- won't matter, as connection will be reset. |
| 2929 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2930 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2931 | }; |
| 2932 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2933 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2934 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2935 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2936 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2937 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2939 | |
| 2940 | rv = callback.WaitForResult(); |
| 2941 | EXPECT_EQ(0, rv); |
| 2942 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2943 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2944 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2945 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2946 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2948 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2949 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2950 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2951 | } |
| 2952 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2953 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2954 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2955 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2956 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2957 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2958 | // reused. See http://crbug.com/544255. |
| 2959 | for (int i = 0; i < 2; ++i) { |
| 2960 | HttpRequestInfo request; |
| 2961 | request.method = "GET"; |
| 2962 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2963 | request.traffic_annotation = |
| 2964 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2965 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2966 | TestNetLog log; |
| 2967 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2969 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2970 | MockWrite data_writes[] = { |
| 2971 | MockWrite(ASYNC, 0, |
| 2972 | "GET / HTTP/1.1\r\n" |
| 2973 | "Host: www.example.org\r\n" |
| 2974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2976 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2977 | // be issuing -- the final header line contains the credentials. |
| 2978 | MockWrite(ASYNC, 6, |
| 2979 | "GET / HTTP/1.1\r\n" |
| 2980 | "Host: www.example.org\r\n" |
| 2981 | "Connection: keep-alive\r\n" |
| 2982 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2983 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2984 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2985 | MockRead data_reads[] = { |
| 2986 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2987 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2988 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2989 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2990 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2991 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2992 | // Lastly, the server responds with the actual content. |
| 2993 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2994 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2995 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2996 | MockRead(ASYNC, 10, "Hello"), |
| 2997 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2998 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2999 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3000 | data.set_busy_before_sync_reads(true); |
| 3001 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3002 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3003 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3005 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3006 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3007 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3008 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3009 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3010 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3011 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3013 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3014 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3015 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3016 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3017 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3019 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3020 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3021 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3022 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3023 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3024 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3025 | TestLoadTimingReused(load_timing_info2); |
| 3026 | // The load timing after restart should have the same socket ID, and times |
| 3027 | // those of the first load timing. |
| 3028 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3029 | load_timing_info2.send_start); |
| 3030 | 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] | 3031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3032 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3033 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3034 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3035 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3036 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3037 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3038 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3039 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3040 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3041 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3042 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3043 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3044 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3048 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3049 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3050 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3051 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3052 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3053 | request.traffic_annotation = |
| 3054 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3055 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3056 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3057 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3058 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3059 | MockWrite("GET / HTTP/1.1\r\n" |
| 3060 | "Host: www.example.org\r\n" |
| 3061 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3063 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3064 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3065 | MockWrite("GET / HTTP/1.1\r\n" |
| 3066 | "Host: www.example.org\r\n" |
| 3067 | "Connection: keep-alive\r\n" |
| 3068 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3069 | }; |
| 3070 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3071 | MockRead data_reads1[] = { |
| 3072 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3073 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3074 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3075 | |
| 3076 | // Lastly, the server responds with the actual content. |
| 3077 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3078 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3079 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3080 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3081 | }; |
| 3082 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3083 | // An incorrect reconnect would cause this to be read. |
| 3084 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3085 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3086 | }; |
| 3087 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3088 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3089 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3090 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3091 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3093 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3096 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3098 | |
| 3099 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3102 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3103 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3104 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3106 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3108 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3109 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3110 | |
| 3111 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3112 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3114 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3115 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3116 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3117 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3121 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3122 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3123 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3124 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3125 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3126 | request.traffic_annotation = |
| 3127 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3128 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3129 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3130 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3131 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3132 | MockWrite("GET / HTTP/1.1\r\n" |
| 3133 | "Host: www.example.org\r\n" |
| 3134 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3136 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3137 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3138 | MockWrite("GET / HTTP/1.1\r\n" |
| 3139 | "Host: www.example.org\r\n" |
| 3140 | "Connection: keep-alive\r\n" |
| 3141 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3142 | }; |
| 3143 | |
| 3144 | // Respond with 5 kb of response body. |
| 3145 | std::string large_body_string("Unauthorized"); |
| 3146 | large_body_string.append(5 * 1024, ' '); |
| 3147 | large_body_string.append("\r\n"); |
| 3148 | |
| 3149 | MockRead data_reads1[] = { |
| 3150 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3151 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3152 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3153 | // 5134 = 12 + 5 * 1024 + 2 |
| 3154 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3155 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3156 | |
| 3157 | // Lastly, the server responds with the actual content. |
| 3158 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3159 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3160 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3161 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3162 | }; |
| 3163 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3164 | // An incorrect reconnect would cause this to be read. |
| 3165 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3166 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3167 | }; |
| 3168 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3169 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3170 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3172 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3174 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3176 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3177 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3179 | |
| 3180 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3181 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3183 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3184 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3185 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3187 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3188 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3189 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3190 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3191 | |
| 3192 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3193 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3195 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3196 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3197 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3198 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3202 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3203 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3204 | HttpRequestInfo request; |
| 3205 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3206 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3207 | request.traffic_annotation = |
| 3208 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3209 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3211 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3212 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3213 | MockWrite( |
| 3214 | "GET / HTTP/1.1\r\n" |
| 3215 | "Host: www.example.org\r\n" |
| 3216 | "Connection: keep-alive\r\n\r\n"), |
| 3217 | // This simulates the seemingly successful write to a closed connection |
| 3218 | // if the bug is not fixed. |
| 3219 | MockWrite( |
| 3220 | "GET / HTTP/1.1\r\n" |
| 3221 | "Host: www.example.org\r\n" |
| 3222 | "Connection: keep-alive\r\n" |
| 3223 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3224 | }; |
| 3225 | |
| 3226 | MockRead data_reads1[] = { |
| 3227 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3228 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3229 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3230 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3231 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3232 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3233 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3234 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3235 | }; |
| 3236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3237 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3238 | // be issuing -- the final header line contains the credentials. |
| 3239 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3240 | MockWrite( |
| 3241 | "GET / HTTP/1.1\r\n" |
| 3242 | "Host: www.example.org\r\n" |
| 3243 | "Connection: keep-alive\r\n" |
| 3244 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3245 | }; |
| 3246 | |
| 3247 | // Lastly, the server responds with the actual content. |
| 3248 | MockRead data_reads2[] = { |
| 3249 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3250 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3251 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3252 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3253 | }; |
| 3254 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3255 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3256 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3257 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3258 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3260 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3263 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3265 | |
| 3266 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3269 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3270 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3271 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3273 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3274 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3275 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3277 | |
| 3278 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3279 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3280 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3281 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3282 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3283 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3284 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3285 | } |
| 3286 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3287 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3288 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3289 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3290 | HttpRequestInfo request; |
| 3291 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3292 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3293 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3294 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3295 | request.traffic_annotation = |
| 3296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3297 | |
| 3298 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3299 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3300 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3301 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3302 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3303 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3305 | |
| 3306 | // Since we have proxy, should try to establish tunnel. |
| 3307 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3308 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3309 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3310 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3311 | }; |
| 3312 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3313 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3314 | // connection. |
| 3315 | MockRead data_reads1[] = { |
| 3316 | // No credentials. |
| 3317 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3318 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3319 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3320 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3321 | // Since the first connection couldn't be reused, need to establish another |
| 3322 | // once given credentials. |
| 3323 | MockWrite data_writes2[] = { |
| 3324 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3325 | // be issuing -- the final header line contains the credentials. |
| 3326 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3327 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3328 | "Proxy-Connection: keep-alive\r\n" |
| 3329 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3330 | |
| 3331 | MockWrite("GET / HTTP/1.1\r\n" |
| 3332 | "Host: www.example.org\r\n" |
| 3333 | "Connection: keep-alive\r\n\r\n"), |
| 3334 | }; |
| 3335 | |
| 3336 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3338 | |
| 3339 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3340 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3341 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3342 | MockRead(SYNCHRONOUS, "hello"), |
| 3343 | }; |
| 3344 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3345 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3346 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3347 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3348 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3349 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3351 | |
| 3352 | TestCompletionCallback callback1; |
| 3353 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3354 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3355 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | |
| 3357 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | |
| 3360 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3361 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3362 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3363 | log.GetEntries(&entries); |
| 3364 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3365 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3366 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3367 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3368 | entries, pos, |
| 3369 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3370 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3371 | |
| 3372 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3373 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3374 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3375 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | EXPECT_EQ(407, response->headers->response_code()); |
| 3377 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3378 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3379 | |
| 3380 | LoadTimingInfo load_timing_info; |
| 3381 | // CONNECT requests and responses are handled at the connect job level, so |
| 3382 | // the transaction does not yet have a connection. |
| 3383 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3384 | |
| 3385 | TestCompletionCallback callback2; |
| 3386 | |
| 3387 | rv = |
| 3388 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3390 | |
| 3391 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3392 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3393 | |
| 3394 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3395 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3396 | |
| 3397 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3398 | EXPECT_EQ(200, response->headers->response_code()); |
| 3399 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3400 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3401 | |
| 3402 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3403 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3404 | |
| 3405 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3406 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3407 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3408 | |
| 3409 | trans.reset(); |
| 3410 | session->CloseAllConnections(); |
| 3411 | } |
| 3412 | |
| 3413 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3414 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3415 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3416 | HttpRequestInfo request; |
| 3417 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3418 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3419 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3420 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3421 | request.traffic_annotation = |
| 3422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3423 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3424 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3425 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3426 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3427 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3428 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3429 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3431 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3432 | // Since we have proxy, should try to establish tunnel. |
| 3433 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3434 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3435 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3436 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3437 | }; |
| 3438 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3439 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3440 | // connection. |
| 3441 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3442 | // No credentials. |
| 3443 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3444 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3445 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3446 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3447 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3448 | MockWrite data_writes2[] = { |
| 3449 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3450 | // be issuing -- the final header line contains the credentials. |
| 3451 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3452 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3453 | "Proxy-Connection: keep-alive\r\n" |
| 3454 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3455 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3456 | MockWrite("GET / HTTP/1.1\r\n" |
| 3457 | "Host: www.example.org\r\n" |
| 3458 | "Connection: keep-alive\r\n\r\n"), |
| 3459 | }; |
| 3460 | |
| 3461 | MockRead data_reads2[] = { |
| 3462 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3463 | |
| 3464 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3465 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3466 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3467 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3468 | }; |
| 3469 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3470 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3471 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3472 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3473 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3474 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3477 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3478 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3479 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3480 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3482 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3484 | |
| 3485 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3486 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3487 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3488 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3489 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3490 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3491 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3492 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3493 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3494 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3495 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3496 | |
| 3497 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3498 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3499 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3500 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3501 | EXPECT_EQ(407, response->headers->response_code()); |
| 3502 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3503 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3504 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3505 | LoadTimingInfo load_timing_info; |
| 3506 | // CONNECT requests and responses are handled at the connect job level, so |
| 3507 | // the transaction does not yet have a connection. |
| 3508 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3510 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3512 | rv = trans->RestartWithAuth( |
| 3513 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3514 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3515 | |
| 3516 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3517 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3518 | |
| 3519 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3520 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3521 | |
| 3522 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3523 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3524 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3525 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3526 | |
| 3527 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3528 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3529 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3530 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3531 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3532 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3533 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3534 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3535 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3536 | } |
| 3537 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3538 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3539 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3540 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3541 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3542 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3543 | // reused. See http://crbug.com/544255. |
| 3544 | for (int i = 0; i < 2; ++i) { |
| 3545 | HttpRequestInfo request; |
| 3546 | request.method = "GET"; |
| 3547 | request.url = GURL("https://www.example.org/"); |
| 3548 | // Ensure that proxy authentication is attempted even |
| 3549 | // when the no authentication data flag is set. |
| 3550 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3551 | request.traffic_annotation = |
| 3552 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3553 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3555 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3556 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3557 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3558 | BoundTestNetLog log; |
| 3559 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3560 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3562 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3563 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3564 | // Since we have proxy, should try to establish tunnel. |
| 3565 | MockWrite data_writes1[] = { |
| 3566 | MockWrite(ASYNC, 0, |
| 3567 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3568 | "Host: www.example.org:443\r\n" |
| 3569 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3571 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3572 | // be issuing -- the final header line contains the credentials. |
| 3573 | MockWrite(ASYNC, 3, |
| 3574 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3575 | "Host: www.example.org:443\r\n" |
| 3576 | "Proxy-Connection: keep-alive\r\n" |
| 3577 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3578 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3579 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3580 | // The proxy responds to the connect with a 407, using a persistent |
| 3581 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3582 | MockRead data_reads1[] = { |
| 3583 | // No credentials. |
| 3584 | MockRead(ASYNC, 1, |
| 3585 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3586 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3587 | "Proxy-Connection: keep-alive\r\n" |
| 3588 | "Content-Length: 10\r\n\r\n"), |
| 3589 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3590 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3591 | // Wrong credentials (wrong password). |
| 3592 | MockRead(ASYNC, 4, |
| 3593 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3594 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3595 | "Proxy-Connection: keep-alive\r\n" |
| 3596 | "Content-Length: 10\r\n\r\n"), |
| 3597 | // No response body because the test stops reading here. |
| 3598 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3599 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3600 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3601 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3602 | data1.set_busy_before_sync_reads(true); |
| 3603 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3604 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3605 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3606 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3607 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3608 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3609 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3610 | TestNetLogEntry::List entries; |
| 3611 | log.GetEntries(&entries); |
| 3612 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3613 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3614 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3615 | ExpectLogContainsSomewhere( |
| 3616 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3617 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3618 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3620 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3621 | ASSERT_TRUE(response); |
| 3622 | ASSERT_TRUE(response->headers); |
| 3623 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3624 | EXPECT_EQ(407, response->headers->response_code()); |
| 3625 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3626 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3627 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3628 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3629 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3630 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3631 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3632 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3633 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3634 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3635 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3636 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3637 | ASSERT_TRUE(response); |
| 3638 | ASSERT_TRUE(response->headers); |
| 3639 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3640 | EXPECT_EQ(407, response->headers->response_code()); |
| 3641 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3642 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3643 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3644 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3645 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3646 | // out of scope. |
| 3647 | session->CloseAllConnections(); |
| 3648 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3652 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3653 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3654 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3655 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3656 | // reused. See http://crbug.com/544255. |
| 3657 | for (int i = 0; i < 2; ++i) { |
| 3658 | HttpRequestInfo request; |
| 3659 | request.method = "GET"; |
| 3660 | request.url = GURL("https://www.example.org/"); |
| 3661 | // Ensure that proxy authentication is attempted even |
| 3662 | // when the no authentication data flag is set. |
| 3663 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3664 | request.traffic_annotation = |
| 3665 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3666 | |
| 3667 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3668 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3669 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3670 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3671 | BoundTestNetLog log; |
| 3672 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3676 | |
| 3677 | // Since we have proxy, should try to establish tunnel. |
| 3678 | MockWrite data_writes1[] = { |
| 3679 | MockWrite(ASYNC, 0, |
| 3680 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3681 | "Host: www.example.org:443\r\n" |
| 3682 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3684 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3685 | // be issuing -- the final header line contains the credentials. |
| 3686 | MockWrite(ASYNC, 3, |
| 3687 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3688 | "Host: www.example.org:443\r\n" |
| 3689 | "Proxy-Connection: keep-alive\r\n" |
| 3690 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3691 | }; |
| 3692 | |
| 3693 | // The proxy responds to the connect with a 407, using a persistent |
| 3694 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3695 | MockRead data_reads1[] = { |
| 3696 | // No credentials. |
| 3697 | MockRead(ASYNC, 1, |
| 3698 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3699 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3700 | "Content-Length: 10\r\n\r\n"), |
| 3701 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3702 | |
| 3703 | // Wrong credentials (wrong password). |
| 3704 | MockRead(ASYNC, 4, |
| 3705 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3706 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3707 | "Content-Length: 10\r\n\r\n"), |
| 3708 | // No response body because the test stops reading here. |
| 3709 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3710 | }; |
| 3711 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3712 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3713 | data1.set_busy_before_sync_reads(true); |
| 3714 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3715 | |
| 3716 | TestCompletionCallback callback1; |
| 3717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3718 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3719 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3720 | |
| 3721 | TestNetLogEntry::List entries; |
| 3722 | log.GetEntries(&entries); |
| 3723 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3724 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3725 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3726 | ExpectLogContainsSomewhere( |
| 3727 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3728 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3729 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3731 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3732 | ASSERT_TRUE(response); |
| 3733 | ASSERT_TRUE(response->headers); |
| 3734 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3735 | EXPECT_EQ(407, response->headers->response_code()); |
| 3736 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3737 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3738 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3739 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3740 | |
| 3741 | TestCompletionCallback callback2; |
| 3742 | |
| 3743 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3744 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3745 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3746 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3748 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3749 | ASSERT_TRUE(response); |
| 3750 | ASSERT_TRUE(response->headers); |
| 3751 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3752 | EXPECT_EQ(407, response->headers->response_code()); |
| 3753 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3754 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3755 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3756 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3757 | |
| 3758 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3759 | // out of scope. |
| 3760 | session->CloseAllConnections(); |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3765 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3766 | // the case the server sends extra data on the original socket, so it can't be |
| 3767 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3768 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3769 | HttpRequestInfo request; |
| 3770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3771 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3772 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3773 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3774 | request.traffic_annotation = |
| 3775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3776 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3777 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3778 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3779 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3780 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3781 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3782 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3784 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3785 | // Since we have proxy, should try to establish tunnel. |
| 3786 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3787 | MockWrite(ASYNC, 0, |
| 3788 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3789 | "Host: www.example.org:443\r\n" |
| 3790 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3791 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3792 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3793 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3794 | // extra data, so the socket cannot be reused. |
| 3795 | MockRead data_reads1[] = { |
| 3796 | // No credentials. |
| 3797 | MockRead(ASYNC, 1, |
| 3798 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3799 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3800 | "Content-Length: 10\r\n\r\n"), |
| 3801 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3802 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3803 | }; |
| 3804 | |
| 3805 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3806 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3807 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3808 | MockWrite(ASYNC, 0, |
| 3809 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3810 | "Host: www.example.org:443\r\n" |
| 3811 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3812 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3813 | |
| 3814 | MockWrite(ASYNC, 2, |
| 3815 | "GET / HTTP/1.1\r\n" |
| 3816 | "Host: www.example.org\r\n" |
| 3817 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3818 | }; |
| 3819 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3820 | MockRead data_reads2[] = { |
| 3821 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3822 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3823 | MockRead(ASYNC, 3, |
| 3824 | "HTTP/1.1 200 OK\r\n" |
| 3825 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3826 | "Content-Length: 5\r\n\r\n"), |
| 3827 | // No response body because the test stops reading here. |
| 3828 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3829 | }; |
| 3830 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3831 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3832 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3833 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3834 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3835 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3836 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3839 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3840 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3841 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3842 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3843 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3844 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3845 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3846 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3847 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3848 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3849 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3850 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3851 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3852 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3853 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3854 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3855 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3856 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3857 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3858 | ASSERT_TRUE(response); |
| 3859 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3860 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3861 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3862 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3863 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3864 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3865 | LoadTimingInfo load_timing_info; |
| 3866 | // CONNECT requests and responses are handled at the connect job level, so |
| 3867 | // the transaction does not yet have a connection. |
| 3868 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3870 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3871 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3872 | rv = |
| 3873 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3874 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3875 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3876 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3877 | EXPECT_EQ(200, response->headers->response_code()); |
| 3878 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3879 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3880 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3881 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3882 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3883 | |
| 3884 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3885 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3886 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3887 | |
| 3888 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3889 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3890 | } |
| 3891 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3892 | // Test the case a proxy closes a socket while the challenge body is being |
| 3893 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3894 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3895 | HttpRequestInfo request; |
| 3896 | request.method = "GET"; |
| 3897 | request.url = GURL("https://www.example.org/"); |
| 3898 | // Ensure that proxy authentication is attempted even |
| 3899 | // when the no authentication data flag is set. |
| 3900 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3901 | request.traffic_annotation = |
| 3902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3903 | |
| 3904 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3905 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3906 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3907 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3910 | |
| 3911 | // Since we have proxy, should try to establish tunnel. |
| 3912 | MockWrite data_writes1[] = { |
| 3913 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3914 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3915 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3916 | }; |
| 3917 | |
| 3918 | // The proxy responds to the connect with a 407, using a persistent |
| 3919 | // connection. |
| 3920 | MockRead data_reads1[] = { |
| 3921 | // No credentials. |
| 3922 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3923 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3924 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3925 | // Server hands up in the middle of the body. |
| 3926 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3927 | }; |
| 3928 | |
| 3929 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3930 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3931 | // be issuing -- the final header line contains the credentials. |
| 3932 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3933 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3934 | "Proxy-Connection: keep-alive\r\n" |
| 3935 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3936 | |
| 3937 | MockWrite("GET / HTTP/1.1\r\n" |
| 3938 | "Host: www.example.org\r\n" |
| 3939 | "Connection: keep-alive\r\n\r\n"), |
| 3940 | }; |
| 3941 | |
| 3942 | MockRead data_reads2[] = { |
| 3943 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3944 | |
| 3945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3946 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3947 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3948 | MockRead(SYNCHRONOUS, "hello"), |
| 3949 | }; |
| 3950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3951 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3953 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3954 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3955 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3957 | |
| 3958 | TestCompletionCallback callback; |
| 3959 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3960 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3961 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3963 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3964 | ASSERT_TRUE(response); |
| 3965 | ASSERT_TRUE(response->headers); |
| 3966 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3967 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3968 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3969 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3970 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3971 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3972 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3973 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3974 | ASSERT_TRUE(response); |
| 3975 | ASSERT_TRUE(response->headers); |
| 3976 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3977 | EXPECT_EQ(200, response->headers->response_code()); |
| 3978 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3979 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3980 | EXPECT_EQ("hello", body); |
| 3981 | } |
| 3982 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3983 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3984 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3985 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3986 | HttpRequestInfo request; |
| 3987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3988 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3989 | request.traffic_annotation = |
| 3990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3991 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3992 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3993 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3994 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3995 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3998 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3999 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4000 | // Since we have proxy, should try to establish tunnel. |
| 4001 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4002 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4003 | "Host: www.example.org:443\r\n" |
| 4004 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4005 | }; |
| 4006 | |
| 4007 | // The proxy responds to the connect with a 407. |
| 4008 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4009 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4010 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4011 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4012 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4013 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4014 | }; |
| 4015 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4016 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4017 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4019 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4020 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4021 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4023 | |
| 4024 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4025 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4027 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4028 | ASSERT_TRUE(response); |
| 4029 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4030 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4031 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4032 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4033 | |
| 4034 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4035 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4036 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4037 | |
| 4038 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4039 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4040 | } |
| 4041 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4042 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4043 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4044 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4045 | HttpRequestInfo request; |
| 4046 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4047 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4048 | request.traffic_annotation = |
| 4049 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4050 | |
| 4051 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4052 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4053 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4057 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4058 | |
| 4059 | // Since we have proxy, should try to establish tunnel. |
| 4060 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4061 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4062 | "Host: www.example.org:443\r\n" |
| 4063 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4064 | }; |
| 4065 | |
| 4066 | // The proxy responds to the connect with a 407. |
| 4067 | MockRead data_reads[] = { |
| 4068 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4069 | MockRead("X-Foo: bar\r\n"), |
| 4070 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4071 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4072 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4073 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4074 | }; |
| 4075 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4076 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4077 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4078 | |
| 4079 | TestCompletionCallback callback; |
| 4080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4081 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4083 | |
| 4084 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4085 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4087 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4088 | ASSERT_TRUE(response); |
| 4089 | ASSERT_TRUE(response->headers); |
| 4090 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4091 | EXPECT_EQ(407, response->headers->response_code()); |
| 4092 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4093 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4094 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4095 | |
| 4096 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4097 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4098 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4099 | |
| 4100 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4101 | session->CloseAllConnections(); |
| 4102 | } |
| 4103 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4104 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4105 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4106 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4107 | HttpRequestInfo request; |
| 4108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4109 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4110 | request.traffic_annotation = |
| 4111 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4112 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4113 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4114 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4116 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4117 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4118 | MockWrite( |
| 4119 | "GET / HTTP/1.1\r\n" |
| 4120 | "Host: www.example.org\r\n" |
| 4121 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4122 | }; |
| 4123 | |
| 4124 | MockRead data_reads1[] = { |
| 4125 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4126 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4127 | // Large content-length -- won't matter, as connection will be reset. |
| 4128 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4129 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4130 | }; |
| 4131 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4132 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4133 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4135 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4136 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4137 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4139 | |
| 4140 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4141 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4142 | } |
| 4143 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4144 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4145 | // through a non-authenticating proxy. The request should fail with |
| 4146 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4147 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4148 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4149 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4150 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4151 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4152 | HttpRequestInfo request; |
| 4153 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4154 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4155 | request.traffic_annotation = |
| 4156 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4157 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4158 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4159 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4160 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4161 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4163 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4164 | // Since we have proxy, should try to establish tunnel. |
| 4165 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4166 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4167 | "Host: www.example.org:443\r\n" |
| 4168 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4169 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4170 | MockWrite("GET / HTTP/1.1\r\n" |
| 4171 | "Host: www.example.org\r\n" |
| 4172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4173 | }; |
| 4174 | |
| 4175 | MockRead data_reads1[] = { |
| 4176 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4177 | |
| 4178 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4179 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4180 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4182 | }; |
| 4183 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4184 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4185 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4186 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4187 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4189 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4190 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4191 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4193 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4195 | |
| 4196 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4197 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4198 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4199 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4200 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4201 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4202 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4203 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4204 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4205 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4206 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4207 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4208 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4209 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4210 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4211 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4212 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4213 | HttpRequestInfo request; |
| 4214 | request.method = "GET"; |
| 4215 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4216 | request.traffic_annotation = |
| 4217 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4218 | |
| 4219 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4220 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4221 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4222 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4223 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4224 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4225 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4226 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4227 | mock_handler->set_allows_default_credentials(true); |
| 4228 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4229 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4230 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4231 | |
| 4232 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4233 | NetLog net_log; |
| 4234 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4235 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4236 | |
| 4237 | // Since we have proxy, should try to establish tunnel. |
| 4238 | MockWrite data_writes1[] = { |
| 4239 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4240 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4241 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4242 | }; |
| 4243 | |
| 4244 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4245 | // connection. |
| 4246 | MockRead data_reads1[] = { |
| 4247 | // No credentials. |
| 4248 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4249 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4250 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4251 | }; |
| 4252 | |
| 4253 | // Since the first connection couldn't be reused, need to establish another |
| 4254 | // once given credentials. |
| 4255 | MockWrite data_writes2[] = { |
| 4256 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4257 | // be issuing -- the final header line contains the credentials. |
| 4258 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4259 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | "Proxy-Connection: keep-alive\r\n" |
| 4261 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4262 | |
| 4263 | MockWrite("GET / HTTP/1.1\r\n" |
| 4264 | "Host: www.example.org\r\n" |
| 4265 | "Connection: keep-alive\r\n\r\n"), |
| 4266 | }; |
| 4267 | |
| 4268 | MockRead data_reads2[] = { |
| 4269 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4270 | |
| 4271 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4273 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4274 | MockRead(SYNCHRONOUS, "hello"), |
| 4275 | }; |
| 4276 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4277 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4278 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4279 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4280 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4281 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4282 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4283 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4284 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4285 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4286 | |
| 4287 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4288 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4289 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4290 | |
| 4291 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4292 | ASSERT_TRUE(response); |
| 4293 | ASSERT_TRUE(response->headers); |
| 4294 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4295 | EXPECT_EQ(407, response->headers->response_code()); |
| 4296 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4297 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4298 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4299 | |
| 4300 | LoadTimingInfo load_timing_info; |
| 4301 | // CONNECT requests and responses are handled at the connect job level, so |
| 4302 | // the transaction does not yet have a connection. |
| 4303 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4304 | |
| 4305 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4306 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4307 | response = trans->GetResponseInfo(); |
| 4308 | ASSERT_TRUE(response); |
| 4309 | ASSERT_TRUE(response->headers); |
| 4310 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4311 | EXPECT_EQ(200, response->headers->response_code()); |
| 4312 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4313 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4314 | |
| 4315 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4316 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4317 | |
| 4318 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4319 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4320 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4321 | |
| 4322 | trans.reset(); |
| 4323 | session->CloseAllConnections(); |
| 4324 | } |
| 4325 | |
| 4326 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4327 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4328 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4329 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4330 | HttpRequestInfo request; |
| 4331 | request.method = "GET"; |
| 4332 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4333 | request.traffic_annotation = |
| 4334 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4335 | |
| 4336 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4337 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4338 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4339 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4340 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4341 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4342 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4343 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4344 | mock_handler->set_allows_default_credentials(true); |
| 4345 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4346 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4347 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4348 | |
| 4349 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4350 | NetLog net_log; |
| 4351 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4352 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4353 | |
| 4354 | // Should try to establish tunnel. |
| 4355 | MockWrite data_writes1[] = { |
| 4356 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4357 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4358 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4359 | |
| 4360 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4361 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4362 | "Proxy-Connection: keep-alive\r\n" |
| 4363 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4364 | }; |
| 4365 | |
| 4366 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4367 | // connection. |
| 4368 | MockRead data_reads1[] = { |
| 4369 | // No credentials. |
| 4370 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4371 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4372 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4373 | }; |
| 4374 | |
| 4375 | // Since the first connection was closed, need to establish another once given |
| 4376 | // credentials. |
| 4377 | MockWrite data_writes2[] = { |
| 4378 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4379 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4380 | "Proxy-Connection: keep-alive\r\n" |
| 4381 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4382 | |
| 4383 | MockWrite("GET / HTTP/1.1\r\n" |
| 4384 | "Host: www.example.org\r\n" |
| 4385 | "Connection: keep-alive\r\n\r\n"), |
| 4386 | }; |
| 4387 | |
| 4388 | MockRead data_reads2[] = { |
| 4389 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4390 | |
| 4391 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4392 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4393 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4394 | MockRead(SYNCHRONOUS, "hello"), |
| 4395 | }; |
| 4396 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4397 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4398 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4399 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4400 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4401 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4403 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4404 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4405 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4406 | |
| 4407 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4408 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4409 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4410 | |
| 4411 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4412 | ASSERT_TRUE(response); |
| 4413 | ASSERT_TRUE(response->headers); |
| 4414 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4415 | EXPECT_EQ(407, response->headers->response_code()); |
| 4416 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4417 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4418 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4419 | |
| 4420 | LoadTimingInfo load_timing_info; |
| 4421 | // CONNECT requests and responses are handled at the connect job level, so |
| 4422 | // the transaction does not yet have a connection. |
| 4423 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4424 | |
| 4425 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4426 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4427 | |
| 4428 | response = trans->GetResponseInfo(); |
| 4429 | ASSERT_TRUE(response); |
| 4430 | ASSERT_TRUE(response->headers); |
| 4431 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4432 | EXPECT_EQ(200, response->headers->response_code()); |
| 4433 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4434 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4435 | |
| 4436 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4437 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4438 | |
| 4439 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4440 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4441 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4442 | |
| 4443 | trans.reset(); |
| 4444 | session->CloseAllConnections(); |
| 4445 | } |
| 4446 | |
| 4447 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4448 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4449 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4450 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4451 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4452 | HttpRequestInfo request; |
| 4453 | request.method = "GET"; |
| 4454 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4455 | request.traffic_annotation = |
| 4456 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4457 | |
| 4458 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4459 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4460 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4461 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4462 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4463 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4464 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4465 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4466 | mock_handler->set_allows_default_credentials(true); |
| 4467 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4468 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4469 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4470 | |
| 4471 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4472 | NetLog net_log; |
| 4473 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4474 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4475 | |
| 4476 | // Should try to establish tunnel. |
| 4477 | MockWrite data_writes1[] = { |
| 4478 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4479 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4480 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4481 | |
| 4482 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4483 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4484 | "Proxy-Connection: keep-alive\r\n" |
| 4485 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4486 | }; |
| 4487 | |
| 4488 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4489 | // second request is sent. |
| 4490 | MockRead data_reads1[] = { |
| 4491 | // No credentials. |
| 4492 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4493 | MockRead("Content-Length: 0\r\n"), |
| 4494 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4495 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4496 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4497 | }; |
| 4498 | |
| 4499 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4500 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4501 | // request. |
| 4502 | MockWrite data_writes2[] = { |
| 4503 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4504 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4505 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4506 | }; |
| 4507 | |
| 4508 | // The proxy, having had more than enough of us, just hangs up. |
| 4509 | MockRead data_reads2[] = { |
| 4510 | // No credentials. |
| 4511 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4512 | }; |
| 4513 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4514 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4516 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4517 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4518 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4519 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4520 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4521 | |
| 4522 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4523 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4524 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4525 | |
| 4526 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4527 | ASSERT_TRUE(response); |
| 4528 | ASSERT_TRUE(response->headers); |
| 4529 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4530 | EXPECT_EQ(407, response->headers->response_code()); |
| 4531 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4532 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4533 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4534 | |
| 4535 | LoadTimingInfo load_timing_info; |
| 4536 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4537 | |
| 4538 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4539 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4540 | |
| 4541 | trans.reset(); |
| 4542 | session->CloseAllConnections(); |
| 4543 | } |
| 4544 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4545 | // This test exercises an odd edge case where the proxy closes the connection |
| 4546 | // after the authentication handshake is complete. Presumably this technique is |
| 4547 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4548 | // succeeds, but the user is not authorized to connect to the destination |
| 4549 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4550 | // site. |
| 4551 | TEST_F(HttpNetworkTransactionTest, |
| 4552 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4553 | HttpRequestInfo request; |
| 4554 | request.method = "GET"; |
| 4555 | request.url = GURL("https://www.example.org/"); |
| 4556 | request.traffic_annotation = |
| 4557 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4558 | |
| 4559 | // Configure against proxy server "myproxy:70". |
| 4560 | session_deps_.proxy_resolution_service = |
| 4561 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4562 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4563 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4564 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4565 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4566 | |
| 4567 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4568 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4569 | // was a real network error. |
| 4570 | // |
| 4571 | // The handlers support both default and explicit credentials. The retry |
| 4572 | // mentioned above should be able to reuse the default identity. Thus there |
| 4573 | // should never be a need to prompt for explicit credentials. |
| 4574 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4575 | mock_handler->set_allows_default_credentials(true); |
| 4576 | mock_handler->set_allows_explicit_credentials(true); |
| 4577 | mock_handler->set_connection_based(true); |
| 4578 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4579 | HttpAuth::AUTH_PROXY); |
| 4580 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4581 | mock_handler->set_allows_default_credentials(true); |
| 4582 | mock_handler->set_allows_explicit_credentials(true); |
| 4583 | mock_handler->set_connection_based(true); |
| 4584 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4585 | HttpAuth::AUTH_PROXY); |
| 4586 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4587 | |
| 4588 | NetLog net_log; |
| 4589 | session_deps_.net_log = &net_log; |
| 4590 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4591 | |
| 4592 | // Data for both sockets. |
| 4593 | // |
| 4594 | // Writes are for the tunnel establishment attempts and the |
| 4595 | // authentication handshake. |
| 4596 | MockWrite data_writes1[] = { |
| 4597 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4598 | "Host: www.example.org:443\r\n" |
| 4599 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4600 | |
| 4601 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4602 | "Host: www.example.org:443\r\n" |
| 4603 | "Proxy-Connection: keep-alive\r\n" |
| 4604 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4605 | |
| 4606 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4607 | "Host: www.example.org:443\r\n" |
| 4608 | "Proxy-Connection: keep-alive\r\n" |
| 4609 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4610 | }; |
| 4611 | |
| 4612 | // The server side of the authentication handshake. Note that the response to |
| 4613 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4614 | MockRead data_reads1[] = { |
| 4615 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4616 | MockRead("Content-Length: 0\r\n"), |
| 4617 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4618 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4619 | |
| 4620 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4621 | MockRead("Content-Length: 0\r\n"), |
| 4622 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4623 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4624 | |
| 4625 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4626 | }; |
| 4627 | |
| 4628 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4629 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4630 | |
| 4631 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4632 | // first attempt. |
| 4633 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4635 | |
| 4636 | auto trans = |
| 4637 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4638 | |
| 4639 | TestCompletionCallback callback; |
| 4640 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4641 | |
| 4642 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4643 | // stack. |
| 4644 | for (int i = 0; i < 4; ++i) { |
| 4645 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4646 | |
| 4647 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4648 | ASSERT_TRUE(response); |
| 4649 | ASSERT_TRUE(response->headers); |
| 4650 | EXPECT_EQ(407, response->headers->response_code()); |
| 4651 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4652 | |
| 4653 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4654 | } |
| 4655 | |
| 4656 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4657 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4658 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4659 | // being the first number, be reached, then lobbest thou thy |
| 4660 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4661 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4662 | |
| 4663 | trans.reset(); |
| 4664 | session->CloseAllConnections(); |
| 4665 | } |
| 4666 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4667 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4668 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4669 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4670 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4671 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4672 | HttpRequestInfo request; |
| 4673 | request.method = "GET"; |
| 4674 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4675 | request.traffic_annotation = |
| 4676 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4677 | |
| 4678 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4679 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4680 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4681 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4682 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4683 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4684 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4685 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4686 | mock_handler->set_allows_default_credentials(true); |
| 4687 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4688 | HttpAuth::AUTH_PROXY); |
| 4689 | // Add another handler for the second challenge. It supports default |
| 4690 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4691 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4692 | mock_handler->set_allows_default_credentials(true); |
| 4693 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4694 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4695 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4696 | |
| 4697 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4698 | NetLog net_log; |
| 4699 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4700 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4701 | |
| 4702 | // Should try to establish tunnel. |
| 4703 | MockWrite data_writes1[] = { |
| 4704 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4705 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4706 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4707 | }; |
| 4708 | |
| 4709 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4710 | // connection. |
| 4711 | MockRead data_reads1[] = { |
| 4712 | // No credentials. |
| 4713 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4714 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4715 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4716 | }; |
| 4717 | |
| 4718 | // Since the first connection was closed, need to establish another once given |
| 4719 | // credentials. |
| 4720 | MockWrite data_writes2[] = { |
| 4721 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4722 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4723 | "Proxy-Connection: keep-alive\r\n" |
| 4724 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4725 | }; |
| 4726 | |
| 4727 | MockRead data_reads2[] = { |
| 4728 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4729 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4730 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4731 | }; |
| 4732 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4733 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4734 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4735 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4736 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4737 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4738 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4739 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4740 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4741 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4742 | |
| 4743 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4744 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4745 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4746 | |
| 4747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4748 | ASSERT_TRUE(response); |
| 4749 | ASSERT_TRUE(response->headers); |
| 4750 | EXPECT_EQ(407, response->headers->response_code()); |
| 4751 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4752 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4753 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4754 | |
| 4755 | LoadTimingInfo load_timing_info; |
| 4756 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4757 | |
| 4758 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4759 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4760 | response = trans->GetResponseInfo(); |
| 4761 | ASSERT_TRUE(response); |
| 4762 | ASSERT_TRUE(response->headers); |
| 4763 | EXPECT_EQ(407, response->headers->response_code()); |
| 4764 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4765 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4766 | |
| 4767 | trans.reset(); |
| 4768 | session->CloseAllConnections(); |
| 4769 | } |
| 4770 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4771 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4772 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4773 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4774 | // authentication handshake can continue with the same scheme but with a |
| 4775 | // different identity. |
| 4776 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4777 | HttpRequestInfo request; |
| 4778 | request.method = "GET"; |
| 4779 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4780 | request.traffic_annotation = |
| 4781 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4782 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4783 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4784 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4785 | |
| 4786 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4787 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4788 | mock_handler->set_allows_default_credentials(true); |
| 4789 | mock_handler->set_allows_explicit_credentials(true); |
| 4790 | mock_handler->set_connection_based(true); |
| 4791 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4792 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4793 | HttpAuth::AUTH_SERVER); |
| 4794 | |
| 4795 | // Add another handler for the second challenge. It supports default |
| 4796 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4797 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4798 | mock_handler->set_allows_default_credentials(true); |
| 4799 | mock_handler->set_allows_explicit_credentials(true); |
| 4800 | mock_handler->set_connection_based(true); |
| 4801 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4802 | HttpAuth::AUTH_SERVER); |
| 4803 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4804 | |
| 4805 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4806 | |
| 4807 | MockWrite data_writes1[] = { |
| 4808 | MockWrite("GET / HTTP/1.1\r\n" |
| 4809 | "Host: www.example.org\r\n" |
| 4810 | "Connection: keep-alive\r\n\r\n"), |
| 4811 | }; |
| 4812 | |
| 4813 | MockRead data_reads1[] = { |
| 4814 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4815 | "WWW-Authenticate: Mock\r\n" |
| 4816 | "Connection: keep-alive\r\n\r\n"), |
| 4817 | }; |
| 4818 | |
| 4819 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4820 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4821 | // transaction procceds without an authorization header. |
| 4822 | MockWrite data_writes2[] = { |
| 4823 | MockWrite("GET / HTTP/1.1\r\n" |
| 4824 | "Host: www.example.org\r\n" |
| 4825 | "Connection: keep-alive\r\n\r\n"), |
| 4826 | }; |
| 4827 | |
| 4828 | MockRead data_reads2[] = { |
| 4829 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4830 | "WWW-Authenticate: Mock\r\n" |
| 4831 | "Connection: keep-alive\r\n\r\n"), |
| 4832 | }; |
| 4833 | |
| 4834 | MockWrite data_writes3[] = { |
| 4835 | MockWrite("GET / HTTP/1.1\r\n" |
| 4836 | "Host: www.example.org\r\n" |
| 4837 | "Connection: keep-alive\r\n" |
| 4838 | "Authorization: auth_token\r\n\r\n"), |
| 4839 | }; |
| 4840 | |
| 4841 | MockRead data_reads3[] = { |
| 4842 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4843 | "Content-Length: 5\r\n" |
| 4844 | "Content-Type: text/plain\r\n" |
| 4845 | "Connection: keep-alive\r\n\r\n" |
| 4846 | "Hello"), |
| 4847 | }; |
| 4848 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4849 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4850 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4851 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4852 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4853 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4854 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4855 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4856 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4857 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4858 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4859 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4860 | |
| 4861 | TestCompletionCallback callback; |
| 4862 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4863 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4864 | |
| 4865 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4866 | ASSERT_TRUE(response); |
| 4867 | ASSERT_TRUE(response->headers); |
| 4868 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4869 | |
| 4870 | // The following three tests assert that an authentication challenge was |
| 4871 | // received and that the stack is ready to respond to the challenge using |
| 4872 | // ambient credentials. |
| 4873 | EXPECT_EQ(401, response->headers->response_code()); |
| 4874 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4875 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4876 | |
| 4877 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4878 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4879 | response = trans->GetResponseInfo(); |
| 4880 | ASSERT_TRUE(response); |
| 4881 | ASSERT_TRUE(response->headers); |
| 4882 | |
| 4883 | // The following three tests assert that an authentication challenge was |
| 4884 | // received and that the stack needs explicit credentials before it is ready |
| 4885 | // to respond to the challenge. |
| 4886 | EXPECT_EQ(401, response->headers->response_code()); |
| 4887 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4888 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4889 | |
| 4890 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4891 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4892 | response = trans->GetResponseInfo(); |
| 4893 | ASSERT_TRUE(response); |
| 4894 | ASSERT_TRUE(response->headers); |
| 4895 | EXPECT_EQ(200, response->headers->response_code()); |
| 4896 | |
| 4897 | trans.reset(); |
| 4898 | session->CloseAllConnections(); |
| 4899 | } |
| 4900 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4901 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4902 | // schemes, based on the path of the URL being requests. |
| 4903 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4904 | public: |
| 4905 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4906 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4907 | |
| 4908 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4909 | |
| 4910 | static HostPortPair ProxyHostPortPair() { |
| 4911 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4912 | } |
| 4913 | |
| 4914 | // ProxyResolver implementation. |
| 4915 | int GetProxyForURL(const GURL& url, |
| 4916 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4917 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4918 | std::unique_ptr<Request>* request, |
| 4919 | const NetLogWithSource& /*net_log*/) override { |
| 4920 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4921 | results->set_traffic_annotation( |
| 4922 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4923 | if (url.path() == "/socks4") { |
| 4924 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4925 | return OK; |
| 4926 | } |
| 4927 | if (url.path() == "/socks5") { |
| 4928 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4929 | return OK; |
| 4930 | } |
| 4931 | if (url.path() == "/http") { |
| 4932 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4933 | return OK; |
| 4934 | } |
| 4935 | if (url.path() == "/https") { |
| 4936 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4937 | return OK; |
| 4938 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4939 | if (url.path() == "/https_trusted") { |
| 4940 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4941 | ProxyHostPortPair(), |
| 4942 | true /* is_trusted_proxy */)); |
| 4943 | return OK; |
| 4944 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4945 | NOTREACHED(); |
| 4946 | return ERR_NOT_IMPLEMENTED; |
| 4947 | } |
| 4948 | |
| 4949 | private: |
| 4950 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4951 | }; |
| 4952 | |
| 4953 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4954 | : public ProxyResolverFactory { |
| 4955 | public: |
| 4956 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4957 | : ProxyResolverFactory(false) {} |
| 4958 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4959 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4960 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4961 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4962 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4963 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4964 | return OK; |
| 4965 | } |
| 4966 | |
| 4967 | private: |
| 4968 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4969 | }; |
| 4970 | |
| 4971 | // 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] | 4972 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4973 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4974 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4975 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4976 | session_deps_.proxy_resolution_service = |
| 4977 | std::make_unique<ProxyResolutionService>( |
| 4978 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4979 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4980 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4981 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4982 | |
| 4983 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4984 | |
| 4985 | MockWrite socks_writes[] = { |
| 4986 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4987 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4988 | MockWrite(SYNCHRONOUS, |
| 4989 | "GET /socks4 HTTP/1.1\r\n" |
| 4990 | "Host: test\r\n" |
| 4991 | "Connection: keep-alive\r\n\r\n"), |
| 4992 | }; |
| 4993 | MockRead socks_reads[] = { |
| 4994 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4995 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4996 | "Connection: keep-alive\r\n" |
| 4997 | "Content-Length: 15\r\n\r\n" |
| 4998 | "SOCKS4 Response"), |
| 4999 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5000 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5001 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 5002 | |
| 5003 | const char kSOCKS5Request[] = { |
| 5004 | 0x05, // Version |
| 5005 | 0x01, // Command (CONNECT) |
| 5006 | 0x00, // Reserved |
| 5007 | 0x03, // Address type (DOMAINNAME) |
| 5008 | 0x04, // Length of domain (4) |
| 5009 | 't', 'e', 's', 't', // Domain string |
| 5010 | 0x00, 0x50, // 16-bit port (80) |
| 5011 | }; |
| 5012 | MockWrite socks5_writes[] = { |
| 5013 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5014 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5015 | MockWrite(SYNCHRONOUS, |
| 5016 | "GET /socks5 HTTP/1.1\r\n" |
| 5017 | "Host: test\r\n" |
| 5018 | "Connection: keep-alive\r\n\r\n"), |
| 5019 | }; |
| 5020 | MockRead socks5_reads[] = { |
| 5021 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5022 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5023 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5024 | "Connection: keep-alive\r\n" |
| 5025 | "Content-Length: 15\r\n\r\n" |
| 5026 | "SOCKS5 Response"), |
| 5027 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5028 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5029 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5030 | |
| 5031 | MockWrite http_writes[] = { |
| 5032 | MockWrite(SYNCHRONOUS, |
| 5033 | "GET http://test/http HTTP/1.1\r\n" |
| 5034 | "Host: test\r\n" |
| 5035 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5036 | }; |
| 5037 | MockRead http_reads[] = { |
| 5038 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5039 | "Proxy-Connection: keep-alive\r\n" |
| 5040 | "Content-Length: 13\r\n\r\n" |
| 5041 | "HTTP Response"), |
| 5042 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5043 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5044 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5045 | |
| 5046 | MockWrite https_writes[] = { |
| 5047 | MockWrite(SYNCHRONOUS, |
| 5048 | "GET http://test/https HTTP/1.1\r\n" |
| 5049 | "Host: test\r\n" |
| 5050 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5051 | }; |
| 5052 | MockRead https_reads[] = { |
| 5053 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5054 | "Proxy-Connection: keep-alive\r\n" |
| 5055 | "Content-Length: 14\r\n\r\n" |
| 5056 | "HTTPS Response"), |
| 5057 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5058 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5059 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5060 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5062 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5063 | MockWrite https_trusted_writes[] = { |
| 5064 | MockWrite(SYNCHRONOUS, |
| 5065 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5066 | "Host: test\r\n" |
| 5067 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5068 | }; |
| 5069 | MockRead https_trusted_reads[] = { |
| 5070 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5071 | "Proxy-Connection: keep-alive\r\n" |
| 5072 | "Content-Length: 22\r\n\r\n" |
| 5073 | "HTTPS Trusted Response"), |
| 5074 | }; |
| 5075 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5076 | https_trusted_writes); |
| 5077 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5078 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5080 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5081 | struct TestCase { |
| 5082 | GURL url; |
| 5083 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5084 | // 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] | 5085 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5086 | int expected_idle_socks4_sockets; |
| 5087 | int expected_idle_socks5_sockets; |
| 5088 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5089 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5090 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5091 | int expected_idle_https_sockets; |
| 5092 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5093 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5094 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5095 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5096 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5097 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5098 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5099 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5100 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5101 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5102 | }; |
| 5103 | |
| 5104 | for (const auto& test_case : kTestCases) { |
| 5105 | HttpRequestInfo request; |
| 5106 | request.method = "GET"; |
| 5107 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5108 | request.traffic_annotation = |
| 5109 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5110 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5111 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5112 | session.get()); |
| 5113 | TestCompletionCallback callback; |
| 5114 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5115 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5116 | |
| 5117 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5118 | ASSERT_TRUE(response); |
| 5119 | ASSERT_TRUE(response->headers); |
| 5120 | EXPECT_EQ(200, response->headers->response_code()); |
| 5121 | std::string response_data; |
| 5122 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5123 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5124 | |
| 5125 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5126 | // the next requests. |
| 5127 | trans.reset(); |
| 5128 | base::RunLoop().RunUntilIdle(); |
| 5129 | |
| 5130 | // Check the number of idle sockets in the pool, to make sure that used |
| 5131 | // sockets are indeed being returned to the socket pool. If each request |
| 5132 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5133 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5134 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5135 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5136 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5137 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5138 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5139 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5140 | ProxyHostPortPair())) |
| 5141 | ->IdleSocketCount()); |
| 5142 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5143 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5144 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5145 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5146 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5147 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5148 | ProxyHostPortPair())) |
| 5149 | ->IdleSocketCount()); |
| 5150 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5151 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5152 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5153 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5154 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5155 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5156 | ProxyHostPortPair())) |
| 5157 | ->IdleSocketCount()); |
| 5158 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5159 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5160 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5161 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5162 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5163 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5164 | ProxyHostPortPair())) |
| 5165 | ->IdleSocketCount()); |
| 5166 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5167 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5168 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5169 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5170 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5171 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5172 | ProxyHostPortPair(), |
| 5173 | true /* is_trusted_proxy */)) |
| 5174 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5175 | } |
| 5176 | } |
| 5177 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5178 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5179 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5180 | HttpRequestInfo request1; |
| 5181 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5182 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5183 | request1.traffic_annotation = |
| 5184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5185 | |
| 5186 | HttpRequestInfo request2; |
| 5187 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5188 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5189 | request2.traffic_annotation = |
| 5190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5191 | |
| 5192 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5193 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5194 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5195 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5196 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5197 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5198 | |
| 5199 | // Since we have proxy, should try to establish tunnel. |
| 5200 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5201 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5202 | "Host: www.example.org:443\r\n" |
| 5203 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5204 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5205 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5206 | "Host: www.example.org\r\n" |
| 5207 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5208 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5209 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5210 | "Host: www.example.org\r\n" |
| 5211 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5212 | }; |
| 5213 | |
| 5214 | // The proxy responds to the connect with a 407, using a persistent |
| 5215 | // connection. |
| 5216 | MockRead data_reads1[] = { |
| 5217 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5218 | |
| 5219 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5220 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5221 | MockRead(SYNCHRONOUS, "1"), |
| 5222 | |
| 5223 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5224 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5225 | MockRead(SYNCHRONOUS, "22"), |
| 5226 | }; |
| 5227 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5228 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5229 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5230 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5232 | |
| 5233 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5234 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5235 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5236 | |
| 5237 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5239 | |
| 5240 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5242 | |
| 5243 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5244 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5245 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5246 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5247 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5248 | |
| 5249 | LoadTimingInfo load_timing_info1; |
| 5250 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5251 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5252 | |
| 5253 | trans1.reset(); |
| 5254 | |
| 5255 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5256 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5257 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5258 | |
| 5259 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5261 | |
| 5262 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5263 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5264 | |
| 5265 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5266 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5267 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5268 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5269 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5270 | |
| 5271 | LoadTimingInfo load_timing_info2; |
| 5272 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5273 | TestLoadTimingReused(load_timing_info2); |
| 5274 | |
| 5275 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5276 | |
| 5277 | trans2.reset(); |
| 5278 | session->CloseAllConnections(); |
| 5279 | } |
| 5280 | |
| 5281 | // 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] | 5282 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5283 | HttpRequestInfo request1; |
| 5284 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5285 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5286 | request1.traffic_annotation = |
| 5287 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5288 | |
| 5289 | HttpRequestInfo request2; |
| 5290 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5291 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5292 | request2.traffic_annotation = |
| 5293 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5294 | |
| 5295 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5296 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5297 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5298 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5299 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5300 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5302 | |
| 5303 | // Since we have proxy, should try to establish tunnel. |
| 5304 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5305 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5306 | "Host: www.example.org:443\r\n" |
| 5307 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5308 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5309 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5310 | "Host: www.example.org\r\n" |
| 5311 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5312 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5313 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5314 | "Host: www.example.org\r\n" |
| 5315 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5316 | }; |
| 5317 | |
| 5318 | // The proxy responds to the connect with a 407, using a persistent |
| 5319 | // connection. |
| 5320 | MockRead data_reads1[] = { |
| 5321 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5322 | |
| 5323 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5324 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5325 | MockRead(SYNCHRONOUS, "1"), |
| 5326 | |
| 5327 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5328 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5329 | MockRead(SYNCHRONOUS, "22"), |
| 5330 | }; |
| 5331 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5332 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5333 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5334 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5336 | |
| 5337 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5338 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5339 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5340 | |
| 5341 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5342 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5343 | |
| 5344 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5345 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5346 | |
| 5347 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5348 | ASSERT_TRUE(response1); |
| 5349 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5350 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5351 | |
| 5352 | LoadTimingInfo load_timing_info1; |
| 5353 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5354 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5355 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5356 | |
| 5357 | trans1.reset(); |
| 5358 | |
| 5359 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5360 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5361 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5362 | |
| 5363 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5364 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5365 | |
| 5366 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5367 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5368 | |
| 5369 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5370 | ASSERT_TRUE(response2); |
| 5371 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5372 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5373 | |
| 5374 | LoadTimingInfo load_timing_info2; |
| 5375 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5376 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5377 | |
| 5378 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5379 | |
| 5380 | trans2.reset(); |
| 5381 | session->CloseAllConnections(); |
| 5382 | } |
| 5383 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5384 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5385 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5386 | HttpRequestInfo request; |
| 5387 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5388 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5389 | request.traffic_annotation = |
| 5390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5391 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5392 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5393 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5394 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5395 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5396 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5398 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5399 | // Since we have proxy, should use full url |
| 5400 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5401 | MockWrite( |
| 5402 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5403 | "Host: www.example.org\r\n" |
| 5404 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5405 | }; |
| 5406 | |
| 5407 | MockRead data_reads1[] = { |
| 5408 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5409 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5410 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5411 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5412 | }; |
| 5413 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5414 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5415 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5416 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5417 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5419 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5420 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5421 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5423 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5425 | |
| 5426 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5427 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5429 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5430 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5431 | TestLoadTimingNotReused(load_timing_info, |
| 5432 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5434 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5435 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5436 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5437 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5438 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5439 | EXPECT_EQ(200, response->headers->response_code()); |
| 5440 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5441 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5442 | |
| 5443 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5444 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5445 | } |
| 5446 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5447 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5448 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5449 | HttpRequestInfo request; |
| 5450 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5451 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5452 | request.traffic_annotation = |
| 5453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5454 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5455 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5456 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5457 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5458 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5459 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5460 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5461 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5462 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5463 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5464 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5465 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5466 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5467 | spdy::SpdySerializedFrame resp( |
| 5468 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5469 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5470 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5471 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5472 | }; |
| 5473 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5474 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5475 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5476 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5477 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5478 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5479 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5481 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5485 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5487 | |
| 5488 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5490 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5491 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5492 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5493 | TestLoadTimingNotReused(load_timing_info, |
| 5494 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5496 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5497 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5498 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5499 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5500 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5501 | |
| 5502 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5503 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5504 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5505 | } |
| 5506 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5507 | // Verifies that a session which races and wins against the owning transaction |
| 5508 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5509 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5510 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5511 | HttpRequestInfo request; |
| 5512 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5513 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5514 | request.traffic_annotation = |
| 5515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5516 | |
| 5517 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5518 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5519 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5520 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5521 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5523 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5524 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5525 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5526 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5527 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5528 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5529 | spdy::SpdySerializedFrame resp( |
| 5530 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5531 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5532 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5533 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5534 | }; |
| 5535 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5536 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5537 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5538 | |
| 5539 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5540 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5542 | |
| 5543 | TestCompletionCallback callback1; |
| 5544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5545 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5546 | |
| 5547 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5548 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5550 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5552 | |
| 5553 | // Race a session to the proxy, which completes first. |
| 5554 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5555 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5556 | PRIVACY_MODE_DISABLED, |
| 5557 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5558 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5559 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5560 | |
| 5561 | // Unstall the resolution begun by the transaction. |
| 5562 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5563 | session_deps_.host_resolver->ResolveAllPending(); |
| 5564 | |
| 5565 | EXPECT_FALSE(callback1.have_result()); |
| 5566 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5567 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5568 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5569 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5570 | ASSERT_TRUE(response); |
| 5571 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5572 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5573 | |
| 5574 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5575 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5576 | EXPECT_EQ(kUploadData, response_data); |
| 5577 | } |
| 5578 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5579 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5580 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5581 | HttpRequestInfo request; |
| 5582 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5583 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5584 | request.traffic_annotation = |
| 5585 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5586 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5587 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5588 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5589 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5590 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5591 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5593 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5594 | // The first request will be a bare GET, the second request will be a |
| 5595 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5596 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5597 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5598 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5599 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5600 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5601 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5602 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5603 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5604 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5605 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5606 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5607 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5608 | }; |
| 5609 | |
| 5610 | // The first response is a 407 proxy authentication challenge, and the second |
| 5611 | // response will be a 200 response since the second request includes a valid |
| 5612 | // Authorization header. |
| 5613 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5614 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5615 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5616 | spdy::SpdySerializedFrame resp_authentication( |
| 5617 | spdy_util_.ConstructSpdyReplyError( |
| 5618 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5619 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5620 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5621 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5622 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5623 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5624 | spdy::SpdySerializedFrame body_data( |
| 5625 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5626 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5627 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5628 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5629 | CreateMockRead(resp_data, 4), |
| 5630 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5631 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | }; |
| 5633 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5634 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5636 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5637 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5638 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5639 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5640 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5641 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5645 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5647 | |
| 5648 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5649 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5651 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5652 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5653 | ASSERT_TRUE(response); |
| 5654 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5655 | EXPECT_EQ(407, response->headers->response_code()); |
| 5656 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5657 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5659 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5661 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5663 | |
| 5664 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5665 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5667 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5668 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5669 | ASSERT_TRUE(response_restart); |
| 5670 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5671 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5672 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5673 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5674 | } |
| 5675 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5676 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5677 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5678 | HttpRequestInfo request; |
| 5679 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5680 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5681 | request.traffic_annotation = |
| 5682 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5683 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5684 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5685 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5686 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5687 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5688 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5691 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5692 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5693 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5694 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5695 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5696 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5697 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5698 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5699 | const char get[] = |
| 5700 | "GET / HTTP/1.1\r\n" |
| 5701 | "Host: www.example.org\r\n" |
| 5702 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5703 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5704 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5705 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5706 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5707 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5708 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5709 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5710 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5711 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5712 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5713 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5714 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5715 | |
| 5716 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5717 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5718 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5719 | }; |
| 5720 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5721 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5722 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5723 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5724 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5725 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5726 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5727 | }; |
| 5728 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5729 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5730 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5731 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5732 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5733 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5734 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5735 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5736 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5738 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5740 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5742 | |
| 5743 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5744 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5745 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5746 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5747 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5748 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5750 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5751 | ASSERT_TRUE(response); |
| 5752 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5753 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5754 | |
| 5755 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5756 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5757 | EXPECT_EQ("1234567890", response_data); |
| 5758 | } |
| 5759 | |
| 5760 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5761 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5762 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5763 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5764 | HttpRequestInfo request; |
| 5765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5766 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5767 | request.traffic_annotation = |
| 5768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5769 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5770 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5771 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5772 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5773 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5774 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5778 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5779 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5780 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5781 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5782 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5783 | // fetch https://www.example.org/ via SPDY |
| 5784 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5785 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5786 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5787 | spdy::SpdySerializedFrame wrapped_get( |
| 5788 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5789 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5790 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5791 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5792 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5793 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5794 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5795 | spdy::SpdySerializedFrame body( |
| 5796 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5797 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5798 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5799 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5800 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5801 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5802 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5803 | |
| 5804 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5805 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5806 | CreateMockWrite(window_update_get_resp, 6), |
| 5807 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5808 | }; |
| 5809 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5810 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5811 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5812 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5813 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5814 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5815 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5816 | }; |
| 5817 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5818 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5819 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5820 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5821 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5822 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5823 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5824 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5825 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5826 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5827 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5828 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5830 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5832 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5833 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5834 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5835 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5836 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5837 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5838 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5839 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5840 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5841 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5842 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5844 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5845 | ASSERT_TRUE(response); |
| 5846 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5847 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5848 | |
| 5849 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5850 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5851 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5855 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5856 | HttpRequestInfo request; |
| 5857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5858 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5859 | request.traffic_annotation = |
| 5860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5861 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5862 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5863 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5864 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5865 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5866 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5870 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5871 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5872 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5873 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5874 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5875 | spdy::SpdySerializedFrame get( |
| 5876 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5877 | |
| 5878 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5879 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5880 | }; |
| 5881 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5882 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5883 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5884 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5885 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5886 | }; |
| 5887 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5888 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5889 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5890 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5891 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5892 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5894 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5895 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5898 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5900 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5902 | |
| 5903 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5904 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5905 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5906 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5907 | } |
| 5908 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5909 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame^] | 5910 | // is observed, but does exist by the time auth credentials are provided. In |
| 5911 | // this case, auth and SSL are fully negotated on the second request, but then |
| 5912 | // the socket is discarded to use the shared session. |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5913 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5914 | ProxyConfig proxy_config; |
| 5915 | proxy_config.set_auto_detect(true); |
| 5916 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5917 | |
| 5918 | CapturingProxyResolver capturing_proxy_resolver; |
| 5919 | capturing_proxy_resolver.set_proxy_server( |
| 5920 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5921 | session_deps_.proxy_resolution_service = |
| 5922 | std::make_unique<ProxyResolutionService>( |
| 5923 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5924 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5925 | std::make_unique<CapturingProxyResolverFactory>( |
| 5926 | &capturing_proxy_resolver), |
| 5927 | nullptr); |
| 5928 | |
| 5929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5930 | |
| 5931 | const char kMyUrl[] = "https://www.example.org/"; |
| 5932 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5933 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5934 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5935 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5936 | |
| 5937 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5938 | spdy::SpdySerializedFrame get2( |
| 5939 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5940 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5941 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5942 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5943 | |
| 5944 | MockWrite auth_challenge_writes[] = { |
| 5945 | MockWrite(ASYNC, 0, |
| 5946 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5947 | "Host: www.example.org:443\r\n" |
| 5948 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame^] | 5949 | MockWrite(ASYNC, 2, |
| 5950 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5951 | "Host: www.example.org:443\r\n" |
| 5952 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5953 | }; |
| 5954 | |
| 5955 | MockRead auth_challenge_reads[] = { |
| 5956 | MockRead(ASYNC, 1, |
| 5957 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5958 | "Content-Length: 0\r\n" |
| 5959 | "Proxy-Connection: close\r\n" |
| 5960 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5961 | }; |
| 5962 | |
| 5963 | MockWrite spdy_writes[] = { |
| 5964 | MockWrite(ASYNC, 0, |
| 5965 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5966 | "Host: www.example.org:443\r\n" |
| 5967 | "Proxy-Connection: keep-alive\r\n" |
| 5968 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5969 | CreateMockWrite(get, 2), |
| 5970 | CreateMockWrite(get2, 5), |
| 5971 | }; |
| 5972 | |
| 5973 | MockRead spdy_reads[] = { |
| 5974 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5975 | CreateMockRead(get_resp, 3, ASYNC), |
| 5976 | CreateMockRead(body, 4, ASYNC), |
| 5977 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5978 | CreateMockRead(body2, 7, ASYNC), |
| 5979 | |
| 5980 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5981 | }; |
| 5982 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame^] | 5983 | MockWrite auth_response_writes_discarded_socket[] = { |
| 5984 | MockWrite(ASYNC, 0, |
| 5985 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5986 | "Host: www.example.org:443\r\n" |
| 5987 | "Proxy-Connection: keep-alive\r\n" |
| 5988 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5989 | }; |
| 5990 | |
| 5991 | MockRead auth_response_reads_discarded_socket[] = { |
| 5992 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5993 | }; |
| 5994 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5995 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5996 | auth_challenge_writes); |
| 5997 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5998 | |
| 5999 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 6000 | auth_challenge_writes); |
| 6001 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 6002 | |
| 6003 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 6004 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 6005 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame^] | 6006 | SequencedSocketData auth_response_discarded_socket( |
| 6007 | auth_response_reads_discarded_socket, |
| 6008 | auth_response_writes_discarded_socket); |
| 6009 | session_deps_.socket_factory->AddSocketDataProvider( |
| 6010 | &auth_response_discarded_socket); |
| 6011 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6012 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6013 | ssl.next_proto = kProtoHTTP2; |
| 6014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6015 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame^] | 6016 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6017 | ssl2.next_proto = kProtoHTTP2; |
| 6018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6019 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6020 | TestCompletionCallback callback; |
| 6021 | std::string response_data; |
| 6022 | |
| 6023 | // Run first request until an auth challenge is observed. |
| 6024 | HttpRequestInfo request1; |
| 6025 | request1.method = "GET"; |
| 6026 | request1.url = GURL(kMyUrl); |
| 6027 | request1.traffic_annotation = |
| 6028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6029 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6030 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6031 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6032 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6033 | ASSERT_TRUE(response); |
| 6034 | ASSERT_TRUE(response->headers); |
| 6035 | EXPECT_EQ(407, response->headers->response_code()); |
| 6036 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6037 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6038 | |
| 6039 | // Run second request until an auth challenge is observed. |
| 6040 | HttpRequestInfo request2; |
| 6041 | request2.method = "GET"; |
| 6042 | request2.url = GURL(kMyUrl); |
| 6043 | request2.traffic_annotation = |
| 6044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6045 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6046 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6047 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6048 | response = trans2.GetResponseInfo(); |
| 6049 | ASSERT_TRUE(response); |
| 6050 | ASSERT_TRUE(response->headers); |
| 6051 | EXPECT_EQ(407, response->headers->response_code()); |
| 6052 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6053 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6054 | |
| 6055 | // Now provide credentials for the first request, and wait for it to complete. |
| 6056 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6057 | rv = callback.GetResult(rv); |
| 6058 | EXPECT_THAT(rv, IsOk()); |
| 6059 | response = trans1.GetResponseInfo(); |
| 6060 | ASSERT_TRUE(response); |
| 6061 | ASSERT_TRUE(response->headers); |
| 6062 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6063 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6064 | EXPECT_EQ(kUploadData, response_data); |
| 6065 | |
| 6066 | // Now provide credentials for the second request. It should notice the |
| 6067 | // existing session, and reuse it. |
| 6068 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6069 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6070 | response = trans2.GetResponseInfo(); |
| 6071 | ASSERT_TRUE(response); |
| 6072 | ASSERT_TRUE(response->headers); |
| 6073 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6074 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6075 | EXPECT_EQ(kUploadData, response_data); |
| 6076 | } |
| 6077 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6078 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6079 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6080 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6081 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6082 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6083 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6084 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6085 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6086 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6087 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6088 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6089 | |
| 6090 | HttpRequestInfo request1; |
| 6091 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6092 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6093 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6094 | request1.traffic_annotation = |
| 6095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6096 | |
| 6097 | HttpRequestInfo request2; |
| 6098 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6099 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6100 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6101 | request2.traffic_annotation = |
| 6102 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6103 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6104 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6105 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6106 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6107 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6108 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6109 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6110 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6111 | // Fetch https://www.example.org/ via HTTP. |
| 6112 | const char get1[] = |
| 6113 | "GET / HTTP/1.1\r\n" |
| 6114 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6115 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6116 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6117 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6118 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6119 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6120 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6121 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6122 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6123 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6124 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6125 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6126 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6127 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6128 | spdy::SpdyHeaderBlock connect2_block; |
| 6129 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6130 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6131 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6132 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6133 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6134 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6135 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6136 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6137 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6138 | // Fetch https://mail.example.org/ via HTTP. |
| 6139 | const char get2[] = |
| 6140 | "GET / HTTP/1.1\r\n" |
| 6141 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6142 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6143 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6144 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6145 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6146 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6147 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6148 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6149 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6150 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6151 | |
| 6152 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6153 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6154 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6155 | }; |
| 6156 | |
| 6157 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6158 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6159 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6160 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6161 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6162 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6163 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6164 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6165 | }; |
| 6166 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6167 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6168 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6169 | |
| 6170 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6171 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6173 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6175 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6177 | |
| 6178 | TestCompletionCallback callback; |
| 6179 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6180 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6181 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6182 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6183 | |
| 6184 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6185 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6186 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6188 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6189 | ASSERT_TRUE(response); |
| 6190 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6191 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6192 | |
| 6193 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6194 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6195 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6196 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6198 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6199 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6200 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6201 | |
| 6202 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6203 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6205 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6206 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6207 | |
| 6208 | // The requests should have different IDs, since they each are using their own |
| 6209 | // separate stream. |
| 6210 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6212 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6213 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6217 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6218 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6220 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6221 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6222 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6223 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6224 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6225 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6226 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6227 | |
| 6228 | HttpRequestInfo request1; |
| 6229 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6230 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6231 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6232 | request1.traffic_annotation = |
| 6233 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6234 | |
| 6235 | HttpRequestInfo request2; |
| 6236 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6237 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6238 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6239 | request2.traffic_annotation = |
| 6240 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6241 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6242 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6243 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6244 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6245 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6246 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6247 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6248 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6249 | // Fetch https://www.example.org/ via HTTP. |
| 6250 | const char get1[] = |
| 6251 | "GET / HTTP/1.1\r\n" |
| 6252 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6253 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6254 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6255 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6256 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6257 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6258 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6259 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6260 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6261 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6262 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6263 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6264 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6265 | // Fetch https://www.example.org/2 via HTTP. |
| 6266 | const char get2[] = |
| 6267 | "GET /2 HTTP/1.1\r\n" |
| 6268 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6269 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6270 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6271 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6272 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6273 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6274 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6275 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6276 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6277 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6278 | |
| 6279 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6280 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6281 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6282 | }; |
| 6283 | |
| 6284 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6285 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6286 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6287 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6288 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6289 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6290 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6291 | }; |
| 6292 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6293 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6294 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6295 | |
| 6296 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6297 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6299 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6300 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6301 | |
| 6302 | TestCompletionCallback callback; |
| 6303 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6304 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6305 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6306 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6307 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6308 | |
| 6309 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6310 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6311 | |
| 6312 | LoadTimingInfo load_timing_info; |
| 6313 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6314 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6315 | |
| 6316 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6317 | ASSERT_TRUE(response); |
| 6318 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6319 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6320 | |
| 6321 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6322 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6323 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6324 | trans.reset(); |
| 6325 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6326 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6327 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6328 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6330 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6331 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6333 | |
| 6334 | LoadTimingInfo load_timing_info2; |
| 6335 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6336 | TestLoadTimingReused(load_timing_info2); |
| 6337 | |
| 6338 | // The requests should have the same ID. |
| 6339 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6340 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6341 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6345 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6346 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6347 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6348 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6349 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6350 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6351 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6352 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6353 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6354 | |
| 6355 | HttpRequestInfo request1; |
| 6356 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6357 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6358 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6359 | request1.traffic_annotation = |
| 6360 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6361 | |
| 6362 | HttpRequestInfo request2; |
| 6363 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6364 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6366 | request2.traffic_annotation = |
| 6367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6368 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6369 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6370 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6371 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6372 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6373 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6374 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6375 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6376 | spdy::SpdySerializedFrame body1( |
| 6377 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6378 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6379 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6380 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6381 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6382 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6383 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6384 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6385 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6386 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6387 | spdy::SpdySerializedFrame body2( |
| 6388 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6389 | |
| 6390 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6391 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6392 | }; |
| 6393 | |
| 6394 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6395 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6396 | CreateMockRead(body1, 2, ASYNC), |
| 6397 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6398 | CreateMockRead(body2, 5, ASYNC), |
| 6399 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6400 | }; |
| 6401 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6402 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6403 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6404 | |
| 6405 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6406 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6408 | |
| 6409 | TestCompletionCallback callback; |
| 6410 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6411 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6412 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6413 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6414 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6415 | |
| 6416 | LoadTimingInfo load_timing_info; |
| 6417 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6418 | TestLoadTimingNotReused(load_timing_info, |
| 6419 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6420 | |
| 6421 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6422 | ASSERT_TRUE(response); |
| 6423 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6424 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6425 | |
| 6426 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6427 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6428 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6429 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6430 | // Delete the first request, so the second one can reuse the socket. |
| 6431 | trans.reset(); |
| 6432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6433 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6434 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6435 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6436 | |
| 6437 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6438 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6439 | TestLoadTimingReused(load_timing_info2); |
| 6440 | |
| 6441 | // The requests should have the same ID. |
| 6442 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6444 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6445 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6446 | } |
| 6447 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6448 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6449 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6450 | // would break socket pool isolation. |
| 6451 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6452 | ProxyConfig proxy_config; |
| 6453 | proxy_config.set_auto_detect(true); |
| 6454 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6455 | |
| 6456 | CapturingProxyResolver capturing_proxy_resolver; |
| 6457 | session_deps_.proxy_resolution_service = |
| 6458 | std::make_unique<ProxyResolutionService>( |
| 6459 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6460 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6461 | std::make_unique<CapturingProxyResolverFactory>( |
| 6462 | &capturing_proxy_resolver), |
| 6463 | nullptr); |
| 6464 | |
| 6465 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6466 | |
| 6467 | SpdyTestUtil spdy_util1; |
| 6468 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6469 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6470 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6471 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6472 | // fetch https://www.example.org/ via HTTP/2. |
| 6473 | const char kMyUrl[] = "https://www.example.org/"; |
| 6474 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6475 | spdy::SpdySerializedFrame wrapped_get( |
| 6476 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6477 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6478 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6479 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6480 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6481 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6482 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6483 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6484 | spdy::SpdySerializedFrame wrapped_body( |
| 6485 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6486 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6487 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6488 | spdy::SpdySerializedFrame window_update_body( |
| 6489 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6490 | |
| 6491 | MockWrite spdy_writes1[] = { |
| 6492 | CreateMockWrite(connect, 0), |
| 6493 | CreateMockWrite(wrapped_get, 2), |
| 6494 | CreateMockWrite(window_update_get_resp, 6), |
| 6495 | CreateMockWrite(window_update_body, 7), |
| 6496 | }; |
| 6497 | |
| 6498 | MockRead spdy_reads1[] = { |
| 6499 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6500 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6501 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6502 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6503 | MockRead(ASYNC, 0, 8), |
| 6504 | }; |
| 6505 | |
| 6506 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6507 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6508 | |
| 6509 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6510 | // a new pipe. |
| 6511 | SpdyTestUtil spdy_util2; |
| 6512 | spdy::SpdySerializedFrame req( |
| 6513 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6514 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6515 | |
| 6516 | spdy::SpdySerializedFrame resp( |
| 6517 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6518 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6519 | MockRead spdy_reads2[] = { |
| 6520 | CreateMockRead(resp, 1), |
| 6521 | CreateMockRead(data, 2), |
| 6522 | MockRead(ASYNC, 0, 3), |
| 6523 | }; |
| 6524 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6525 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6526 | |
| 6527 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6528 | ssl.next_proto = kProtoHTTP2; |
| 6529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6530 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6531 | ssl2.next_proto = kProtoHTTP2; |
| 6532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6533 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6534 | ssl3.next_proto = kProtoHTTP2; |
| 6535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6536 | |
| 6537 | TestCompletionCallback callback; |
| 6538 | std::string response_data; |
| 6539 | |
| 6540 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6541 | capturing_proxy_resolver.set_proxy_server( |
| 6542 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6543 | HttpRequestInfo request1; |
| 6544 | request1.method = "GET"; |
| 6545 | request1.url = GURL("https://www.example.org/"); |
| 6546 | request1.traffic_annotation = |
| 6547 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6548 | |
| 6549 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6550 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6552 | |
| 6553 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6554 | base::RunLoop().RunUntilIdle(); |
| 6555 | // Now allow the read of the response to complete. |
| 6556 | spdy_data1.Resume(); |
| 6557 | rv = callback.WaitForResult(); |
| 6558 | EXPECT_THAT(rv, IsOk()); |
| 6559 | |
| 6560 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6561 | ASSERT_TRUE(response); |
| 6562 | ASSERT_TRUE(response->headers); |
| 6563 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6564 | |
| 6565 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6566 | EXPECT_EQ(kUploadData, response_data); |
| 6567 | RunUntilIdle(); |
| 6568 | |
| 6569 | // Make a direct HTTP/2 request to proxy:70. |
| 6570 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6571 | HttpRequestInfo request2; |
| 6572 | request2.method = "GET"; |
| 6573 | request2.url = GURL("https://proxy:70/"); |
| 6574 | request2.traffic_annotation = |
| 6575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6576 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6577 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6578 | NetLogWithSource())), |
| 6579 | IsOk()); |
| 6580 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6581 | } |
| 6582 | |
| 6583 | // Same as above, but reverse request order, since the code to check for an |
| 6584 | // existing session is different for tunnels and direct connections. |
| 6585 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6586 | // Configure against https proxy server "myproxy:80". |
| 6587 | ProxyConfig proxy_config; |
| 6588 | proxy_config.set_auto_detect(true); |
| 6589 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6590 | |
| 6591 | CapturingProxyResolver capturing_proxy_resolver; |
| 6592 | session_deps_.proxy_resolution_service = |
| 6593 | std::make_unique<ProxyResolutionService>( |
| 6594 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6595 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6596 | std::make_unique<CapturingProxyResolverFactory>( |
| 6597 | &capturing_proxy_resolver), |
| 6598 | nullptr); |
| 6599 | |
| 6600 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6601 | // Fetch https://proxy:70/ via HTTP/2. |
| 6602 | SpdyTestUtil spdy_util1; |
| 6603 | spdy::SpdySerializedFrame req( |
| 6604 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6605 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6606 | |
| 6607 | spdy::SpdySerializedFrame resp( |
| 6608 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6609 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6610 | MockRead spdy_reads1[] = { |
| 6611 | CreateMockRead(resp, 1), |
| 6612 | CreateMockRead(data, 2), |
| 6613 | MockRead(ASYNC, 0, 3), |
| 6614 | }; |
| 6615 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6616 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6617 | |
| 6618 | SpdyTestUtil spdy_util2; |
| 6619 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6620 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6621 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6622 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6623 | // fetch https://www.example.org/ via HTTP/2. |
| 6624 | const char kMyUrl[] = "https://www.example.org/"; |
| 6625 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6626 | spdy::SpdySerializedFrame wrapped_get( |
| 6627 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6628 | spdy::SpdySerializedFrame conn_resp( |
| 6629 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6630 | spdy::SpdySerializedFrame get_resp( |
| 6631 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6632 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6633 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6634 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6635 | spdy::SpdySerializedFrame wrapped_body( |
| 6636 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6637 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6638 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6639 | spdy::SpdySerializedFrame window_update_body( |
| 6640 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6641 | |
| 6642 | MockWrite spdy_writes2[] = { |
| 6643 | CreateMockWrite(connect, 0), |
| 6644 | CreateMockWrite(wrapped_get, 2), |
| 6645 | CreateMockWrite(window_update_get_resp, 6), |
| 6646 | CreateMockWrite(window_update_body, 7), |
| 6647 | }; |
| 6648 | |
| 6649 | MockRead spdy_reads2[] = { |
| 6650 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6651 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6652 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6653 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6654 | MockRead(ASYNC, 0, 8), |
| 6655 | }; |
| 6656 | |
| 6657 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6658 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6659 | |
| 6660 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6661 | ssl.next_proto = kProtoHTTP2; |
| 6662 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6663 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6664 | ssl2.next_proto = kProtoHTTP2; |
| 6665 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6666 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6667 | ssl3.next_proto = kProtoHTTP2; |
| 6668 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6669 | |
| 6670 | TestCompletionCallback callback; |
| 6671 | std::string response_data; |
| 6672 | |
| 6673 | // Make a direct HTTP/2 request to proxy:70. |
| 6674 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6675 | HttpRequestInfo request1; |
| 6676 | request1.method = "GET"; |
| 6677 | request1.url = GURL("https://proxy:70/"); |
| 6678 | request1.traffic_annotation = |
| 6679 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6680 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6681 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6682 | NetLogWithSource())), |
| 6683 | IsOk()); |
| 6684 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6685 | RunUntilIdle(); |
| 6686 | |
| 6687 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6688 | capturing_proxy_resolver.set_proxy_server( |
| 6689 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6690 | HttpRequestInfo request2; |
| 6691 | request2.method = "GET"; |
| 6692 | request2.url = GURL("https://www.example.org/"); |
| 6693 | request2.traffic_annotation = |
| 6694 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6695 | |
| 6696 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6697 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6699 | |
| 6700 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6701 | base::RunLoop().RunUntilIdle(); |
| 6702 | // Now allow the read of the response to complete. |
| 6703 | spdy_data2.Resume(); |
| 6704 | rv = callback.WaitForResult(); |
| 6705 | EXPECT_THAT(rv, IsOk()); |
| 6706 | |
| 6707 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6708 | ASSERT_TRUE(response2); |
| 6709 | ASSERT_TRUE(response2->headers); |
| 6710 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6711 | |
| 6712 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6713 | EXPECT_EQ(kUploadData, response_data); |
| 6714 | } |
| 6715 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6716 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6717 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6718 | HttpRequestInfo request; |
| 6719 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6720 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6721 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6722 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6723 | request.traffic_annotation = |
| 6724 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6725 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6726 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6727 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6728 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6729 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6730 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6732 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6733 | // Since we have proxy, should use full url |
| 6734 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6735 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6736 | "Host: www.example.org\r\n" |
| 6737 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6739 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6740 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6741 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6742 | "Host: www.example.org\r\n" |
| 6743 | "Proxy-Connection: keep-alive\r\n" |
| 6744 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6745 | }; |
| 6746 | |
| 6747 | // The proxy responds to the GET with a 407, using a persistent |
| 6748 | // connection. |
| 6749 | MockRead data_reads1[] = { |
| 6750 | // No credentials. |
| 6751 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6752 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6753 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6754 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6755 | |
| 6756 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6757 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6758 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6759 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6760 | }; |
| 6761 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6762 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6763 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6764 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6766 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6767 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6771 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6773 | |
| 6774 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6775 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6776 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6777 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6778 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6779 | TestLoadTimingNotReused(load_timing_info, |
| 6780 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6782 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6783 | ASSERT_TRUE(response); |
| 6784 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6785 | EXPECT_EQ(407, response->headers->response_code()); |
| 6786 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6787 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6788 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6790 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6792 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6794 | |
| 6795 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6797 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6798 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6799 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6800 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6801 | TestLoadTimingReused(load_timing_info); |
| 6802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6803 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6804 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6805 | |
| 6806 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6807 | EXPECT_EQ(200, response->headers->response_code()); |
| 6808 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6809 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6810 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6811 | |
| 6812 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6813 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6814 | } |
| 6815 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6816 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6817 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6818 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6819 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6820 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6821 | request.traffic_annotation = |
| 6822 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6823 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6824 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6825 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6826 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6828 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6829 | // Since we have proxy, should try to establish tunnel. |
| 6830 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6831 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6832 | "Host: www.example.org:443\r\n" |
| 6833 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6834 | }; |
| 6835 | |
| 6836 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6837 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6838 | // No response body because the test stops reading here. |
| 6839 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6840 | }; |
| 6841 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6842 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6845 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6848 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6849 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6851 | |
| 6852 | rv = callback.WaitForResult(); |
| 6853 | EXPECT_EQ(expected_status, rv); |
| 6854 | } |
| 6855 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6856 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6857 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6858 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6859 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6860 | } |
| 6861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6862 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6863 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6864 | } |
| 6865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6866 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6867 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6868 | } |
| 6869 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6870 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6871 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6872 | } |
| 6873 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6874 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6875 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6876 | } |
| 6877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6878 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6879 | ConnectStatusHelper( |
| 6880 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6881 | } |
| 6882 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6883 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6884 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6885 | } |
| 6886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6887 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6888 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6889 | } |
| 6890 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6891 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6892 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6893 | } |
| 6894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6895 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6896 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6897 | } |
| 6898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6899 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6900 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6901 | } |
| 6902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6903 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6904 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6905 | } |
| 6906 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6907 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6908 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6909 | } |
| 6910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6911 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6912 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6913 | } |
| 6914 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6915 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6916 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6917 | } |
| 6918 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6919 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6920 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6921 | } |
| 6922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6923 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6924 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6925 | } |
| 6926 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6927 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6928 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6929 | } |
| 6930 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6931 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6932 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6933 | } |
| 6934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6935 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6936 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6937 | } |
| 6938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6939 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6940 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6941 | } |
| 6942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6943 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6944 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6945 | } |
| 6946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6947 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6948 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6949 | } |
| 6950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6951 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6952 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6953 | } |
| 6954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6956 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelperWithExpectedStatus( |
| 6961 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6962 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6963 | } |
| 6964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6965 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6966 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6967 | } |
| 6968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6969 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6970 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6971 | } |
| 6972 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6973 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6974 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6975 | } |
| 6976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6977 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6978 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6979 | } |
| 6980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6981 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6982 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6983 | } |
| 6984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6985 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6986 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6987 | } |
| 6988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6989 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6990 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6991 | } |
| 6992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6993 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6994 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6995 | } |
| 6996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6997 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6998 | ConnectStatusHelper( |
| 6999 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 7000 | } |
| 7001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7002 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7003 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 7004 | } |
| 7005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7006 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7007 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 7008 | } |
| 7009 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7010 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7011 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 7012 | } |
| 7013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7014 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7015 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 7016 | } |
| 7017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7018 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7019 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 7020 | } |
| 7021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7022 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7023 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 7024 | } |
| 7025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7026 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7027 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 7028 | } |
| 7029 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7030 | // Test the flow when both the proxy server AND origin server require |
| 7031 | // authentication. Again, this uses basic auth for both since that is |
| 7032 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7033 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7034 | HttpRequestInfo request; |
| 7035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7036 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7037 | request.traffic_annotation = |
| 7038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7039 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7040 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7041 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7042 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7043 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7045 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7046 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7047 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7048 | MockWrite( |
| 7049 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7050 | "Host: www.example.org\r\n" |
| 7051 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7052 | }; |
| 7053 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7054 | MockRead data_reads1[] = { |
| 7055 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7056 | // Give a couple authenticate options (only the middle one is actually |
| 7057 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7058 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7059 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7060 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7061 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7062 | // Large content-length -- won't matter, as connection will be reset. |
| 7063 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7064 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7065 | }; |
| 7066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7067 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7068 | // request we should be issuing -- the final header line contains the |
| 7069 | // proxy's credentials. |
| 7070 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7071 | MockWrite( |
| 7072 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7073 | "Host: www.example.org\r\n" |
| 7074 | "Proxy-Connection: keep-alive\r\n" |
| 7075 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7076 | }; |
| 7077 | |
| 7078 | // Now the proxy server lets the request pass through to origin server. |
| 7079 | // The origin server responds with a 401. |
| 7080 | MockRead data_reads2[] = { |
| 7081 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7082 | // Note: We are using the same realm-name as the proxy server. This is |
| 7083 | // completely valid, as realms are unique across hosts. |
| 7084 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7085 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7086 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7087 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7088 | }; |
| 7089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7090 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7091 | // the credentials for both the proxy and origin server. |
| 7092 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7093 | MockWrite( |
| 7094 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7095 | "Host: www.example.org\r\n" |
| 7096 | "Proxy-Connection: keep-alive\r\n" |
| 7097 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7098 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7099 | }; |
| 7100 | |
| 7101 | // Lastly we get the desired content. |
| 7102 | MockRead data_reads3[] = { |
| 7103 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7104 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7105 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7106 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7107 | }; |
| 7108 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7109 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7110 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7111 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7112 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7113 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7114 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7116 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7117 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7118 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7120 | |
| 7121 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7122 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7124 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7125 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7126 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7128 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7130 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7132 | |
| 7133 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7136 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7137 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7138 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7140 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7142 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7143 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7144 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7145 | |
| 7146 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7147 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7149 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7150 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7151 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7152 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7153 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7154 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7155 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7156 | // authorization headers. |
| 7157 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7158 | // The NTLM authentication unit tests are based on known test data from the |
| 7159 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7160 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7161 | // for the implementation and testing of the protocol. |
| 7162 | // |
| 7163 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7164 | |
| 7165 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7166 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7167 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7168 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7169 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7170 | request.traffic_annotation = |
| 7171 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7172 | |
| 7173 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7174 | // to other auth schemes. |
| 7175 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7176 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7177 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7178 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7180 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7181 | // Generate the NTLM messages based on known test data. |
| 7182 | std::string negotiate_msg; |
| 7183 | std::string challenge_msg; |
| 7184 | std::string authenticate_msg; |
| 7185 | base::Base64Encode( |
| 7186 | base::StringPiece( |
| 7187 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7188 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7189 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7190 | base::Base64Encode( |
| 7191 | base::StringPiece( |
| 7192 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7193 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7194 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7195 | base::Base64Encode( |
| 7196 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7197 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7198 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7199 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7200 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7201 | &authenticate_msg); |
| 7202 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7203 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7204 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7205 | "Host: server\r\n" |
| 7206 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7207 | }; |
| 7208 | |
| 7209 | MockRead data_reads1[] = { |
| 7210 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7211 | // Negotiate and NTLM are often requested together. However, we only want |
| 7212 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7213 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7214 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7215 | MockRead("Connection: close\r\n"), |
| 7216 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7217 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7218 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7219 | }; |
| 7220 | |
| 7221 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7222 | // After restarting with a null identity, this is the |
| 7223 | // request we should be issuing -- the final header line contains a Type |
| 7224 | // 1 message. |
| 7225 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7226 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7227 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7228 | "Authorization: NTLM "), |
| 7229 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7231 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7232 | // (using correct credentials). The second request continues on the |
| 7233 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7234 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7235 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7236 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7237 | "Authorization: NTLM "), |
| 7238 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7239 | }; |
| 7240 | |
| 7241 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7242 | // The origin server responds with a Type 2 message. |
| 7243 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7244 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7245 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7246 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7247 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7248 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7249 | // Lastly we get the desired content. |
| 7250 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7251 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7252 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7253 | }; |
| 7254 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7255 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7256 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7257 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7258 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7259 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7260 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7262 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7265 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7266 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7267 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7268 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7269 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7271 | |
| 7272 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7274 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7275 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7277 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7278 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7279 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7281 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7282 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7283 | rv = trans.RestartWithAuth( |
| 7284 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7285 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7287 | |
| 7288 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7289 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7290 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7291 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7293 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7294 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7295 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7297 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7299 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7300 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7301 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7302 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7303 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7304 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7305 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7306 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7307 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7308 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7309 | |
| 7310 | std::string response_data; |
| 7311 | rv = ReadTransaction(&trans, &response_data); |
| 7312 | EXPECT_THAT(rv, IsOk()); |
| 7313 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7314 | |
| 7315 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7316 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7317 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7318 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7319 | } |
| 7320 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7321 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7322 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7323 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7324 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7325 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7326 | request.traffic_annotation = |
| 7327 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7328 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7329 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7330 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7332 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7333 | // Generate the NTLM messages based on known test data. |
| 7334 | std::string negotiate_msg; |
| 7335 | std::string challenge_msg; |
| 7336 | std::string authenticate_msg; |
| 7337 | base::Base64Encode( |
| 7338 | base::StringPiece( |
| 7339 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7340 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7341 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7342 | base::Base64Encode( |
| 7343 | base::StringPiece( |
| 7344 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7345 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7346 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7347 | base::Base64Encode( |
| 7348 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7349 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7350 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7351 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7352 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7353 | &authenticate_msg); |
| 7354 | |
| 7355 | // The authenticate message when |kWrongPassword| is sent. |
| 7356 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7357 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7358 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7359 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7360 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7361 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7362 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7363 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7364 | // Sanity check that it's the same length as the correct authenticate message |
| 7365 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7366 | ASSERT_EQ(authenticate_msg.length(), |
| 7367 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7368 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7369 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7370 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7371 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7372 | "Host: server\r\n" |
| 7373 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7374 | }; |
| 7375 | |
| 7376 | MockRead data_reads1[] = { |
| 7377 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7378 | // Negotiate and NTLM are often requested together. However, we only want |
| 7379 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7380 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7381 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7382 | MockRead("Connection: close\r\n"), |
| 7383 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7384 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7385 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7386 | }; |
| 7387 | |
| 7388 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7389 | // After restarting with a null identity, this is the |
| 7390 | // request we should be issuing -- the final header line contains a Type |
| 7391 | // 1 message. |
| 7392 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7393 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7394 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7395 | "Authorization: NTLM "), |
| 7396 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7398 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7399 | // (using incorrect credentials). The second request continues on the |
| 7400 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7401 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7402 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7403 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7404 | "Authorization: NTLM "), |
| 7405 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7406 | }; |
| 7407 | |
| 7408 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7409 | // The origin server responds with a Type 2 message. |
| 7410 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7411 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7412 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7413 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7414 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7415 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7416 | // Wrong password. |
| 7417 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7418 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7419 | MockRead("Content-Length: 42\r\n"), |
| 7420 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7421 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7422 | }; |
| 7423 | |
| 7424 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7425 | // After restarting with a null identity, this is the |
| 7426 | // request we should be issuing -- the final header line contains a Type |
| 7427 | // 1 message. |
| 7428 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7429 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7430 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7431 | "Authorization: NTLM "), |
| 7432 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7434 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7435 | // (the credentials for the origin server). The second request continues |
| 7436 | // on the same connection. |
| 7437 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7438 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7439 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7440 | "Authorization: NTLM "), |
| 7441 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7442 | }; |
| 7443 | |
| 7444 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7445 | // The origin server responds with a Type 2 message. |
| 7446 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7447 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7448 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7449 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7450 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7451 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7452 | // Lastly we get the desired content. |
| 7453 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7454 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7455 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7456 | }; |
| 7457 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7458 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7459 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7460 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7461 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7462 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7463 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7464 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7465 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7467 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7469 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7472 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7475 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7476 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7478 | |
| 7479 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7482 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7484 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7485 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7486 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7488 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7489 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7490 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7491 | rv = trans.RestartWithAuth( |
| 7492 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7493 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7495 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7496 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7499 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7500 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7501 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7503 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7504 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7505 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7507 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7508 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7509 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7510 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7511 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7512 | |
| 7513 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7514 | rv = trans.RestartWithAuth( |
| 7515 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7516 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7518 | |
| 7519 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7520 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7522 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7524 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7525 | |
| 7526 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7527 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7528 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7529 | |
| 7530 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7531 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7533 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7534 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7535 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7536 | |
| 7537 | std::string response_data; |
| 7538 | rv = ReadTransaction(&trans, &response_data); |
| 7539 | EXPECT_THAT(rv, IsOk()); |
| 7540 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7541 | |
| 7542 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7543 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7544 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7545 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7546 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7547 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7548 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7549 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7550 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7551 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7552 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7553 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7554 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7555 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7556 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7557 | |
| 7558 | HttpRequestInfo request; |
| 7559 | request.method = "GET"; |
| 7560 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7561 | request.traffic_annotation = |
| 7562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7563 | |
| 7564 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7565 | spdy::SpdyHeaderBlock request_headers0( |
| 7566 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7567 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7568 | 1, std::move(request_headers0), LOWEST, true)); |
| 7569 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7570 | spdy::SpdyHeaderBlock response_headers0; |
| 7571 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7572 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7573 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7574 | 1, std::move(response_headers0), true)); |
| 7575 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7576 | // Stream 1 is closed. |
| 7577 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7578 | |
| 7579 | // Generate the NTLM messages based on known test data. |
| 7580 | std::string negotiate_msg; |
| 7581 | std::string challenge_msg; |
| 7582 | std::string authenticate_msg; |
| 7583 | base::Base64Encode( |
| 7584 | base::StringPiece( |
| 7585 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7586 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7587 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7588 | base::Base64Encode( |
| 7589 | base::StringPiece( |
| 7590 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7591 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7592 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7593 | base::Base64Encode( |
| 7594 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7595 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7596 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7597 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7598 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7599 | &authenticate_msg); |
| 7600 | |
| 7601 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7602 | spdy::SpdyHeaderBlock request_headers1( |
| 7603 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7604 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7605 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7606 | 3, std::move(request_headers1), LOWEST, true)); |
| 7607 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7608 | spdy::SpdySerializedFrame rst( |
| 7609 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7610 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7611 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7612 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7613 | |
| 7614 | // Retry yet again using HTTP/1.1. |
| 7615 | MockWrite writes1[] = { |
| 7616 | // After restarting with a null identity, this is the |
| 7617 | // request we should be issuing -- the final header line contains a Type |
| 7618 | // 1 message. |
| 7619 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7620 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7621 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7622 | "Authorization: NTLM "), |
| 7623 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7624 | |
| 7625 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7626 | // (the credentials for the origin server). The second request continues |
| 7627 | // on the same connection. |
| 7628 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7629 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7630 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7631 | "Authorization: NTLM "), |
| 7632 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7633 | }; |
| 7634 | |
| 7635 | MockRead reads1[] = { |
| 7636 | // The origin server responds with a Type 2 message. |
| 7637 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7638 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7639 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7640 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7641 | MockRead("You are not authorized to view this page\r\n"), |
| 7642 | |
| 7643 | // Lastly we get the desired content. |
| 7644 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7645 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7646 | 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] | 7647 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7648 | SequencedSocketData data0(reads0, writes0); |
| 7649 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7650 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7651 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7652 | |
| 7653 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7654 | ssl0.next_proto = kProtoHTTP2; |
| 7655 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7658 | |
| 7659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7661 | |
| 7662 | TestCompletionCallback callback1; |
| 7663 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7665 | |
| 7666 | rv = callback1.WaitForResult(); |
| 7667 | EXPECT_THAT(rv, IsOk()); |
| 7668 | |
| 7669 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7670 | |
| 7671 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7672 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7673 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7674 | |
| 7675 | TestCompletionCallback callback2; |
| 7676 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7677 | rv = trans.RestartWithAuth( |
| 7678 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7679 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7681 | |
| 7682 | rv = callback2.WaitForResult(); |
| 7683 | EXPECT_THAT(rv, IsOk()); |
| 7684 | |
| 7685 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7686 | |
| 7687 | response = trans.GetResponseInfo(); |
| 7688 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7689 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7690 | |
| 7691 | TestCompletionCallback callback3; |
| 7692 | |
| 7693 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7695 | |
| 7696 | rv = callback3.WaitForResult(); |
| 7697 | EXPECT_THAT(rv, IsOk()); |
| 7698 | |
| 7699 | response = trans.GetResponseInfo(); |
| 7700 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7701 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7702 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7703 | |
| 7704 | std::string response_data; |
| 7705 | rv = ReadTransaction(&trans, &response_data); |
| 7706 | EXPECT_THAT(rv, IsOk()); |
| 7707 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7708 | |
| 7709 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7710 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7711 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7712 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7713 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7714 | |
| 7715 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7716 | // do no retry forever checking for TLS version interference. This is a |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7717 | // regression test for https://crbug.com/823387. The version interference probe |
| 7718 | // has since been removed, but retain the regression test so we can update it if |
| 7719 | // we add future TLS retries. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7720 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7721 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7722 | // https://origin/. |
| 7723 | session_deps_.proxy_resolution_service = |
| 7724 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7725 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7726 | |
| 7727 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7728 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7729 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7730 | |
| 7731 | HttpRequestInfo request; |
| 7732 | request.method = "GET"; |
| 7733 | request.url = GURL("https://origin/"); |
| 7734 | request.traffic_annotation = |
| 7735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7736 | |
| 7737 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7738 | // to other auth schemes. |
| 7739 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7740 | |
| 7741 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7742 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7744 | |
| 7745 | // Generate the NTLM messages based on known test data. |
| 7746 | std::string negotiate_msg; |
| 7747 | std::string challenge_msg; |
| 7748 | std::string authenticate_msg; |
| 7749 | base::Base64Encode( |
| 7750 | base::StringPiece( |
| 7751 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7752 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7753 | &negotiate_msg); |
| 7754 | base::Base64Encode( |
| 7755 | base::StringPiece( |
| 7756 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7757 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7758 | &challenge_msg); |
| 7759 | base::Base64Encode( |
| 7760 | base::StringPiece( |
| 7761 | reinterpret_cast<const char*>( |
| 7762 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7763 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7764 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7765 | &authenticate_msg); |
| 7766 | |
| 7767 | MockWrite data_writes[] = { |
| 7768 | // The initial CONNECT request. |
| 7769 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7770 | "Host: origin:443\r\n" |
| 7771 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7772 | |
| 7773 | // After restarting with an identity. |
| 7774 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7775 | "Host: origin:443\r\n" |
| 7776 | "Proxy-Connection: keep-alive\r\n" |
| 7777 | "Proxy-Authorization: NTLM "), |
| 7778 | MockWrite(negotiate_msg.c_str()), |
| 7779 | // End headers. |
| 7780 | MockWrite("\r\n\r\n"), |
| 7781 | |
| 7782 | // The second restart. |
| 7783 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7784 | "Host: origin:443\r\n" |
| 7785 | "Proxy-Connection: keep-alive\r\n" |
| 7786 | "Proxy-Authorization: NTLM "), |
| 7787 | MockWrite(authenticate_msg.c_str()), |
| 7788 | // End headers. |
| 7789 | MockWrite("\r\n\r\n"), |
| 7790 | }; |
| 7791 | |
| 7792 | MockRead data_reads[] = { |
| 7793 | // The initial NTLM response. |
| 7794 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7795 | "Content-Length: 0\r\n" |
| 7796 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7797 | |
| 7798 | // The NTLM challenge message. |
| 7799 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7800 | "Content-Length: 0\r\n" |
| 7801 | "Proxy-Authenticate: NTLM "), |
| 7802 | MockRead(challenge_msg.c_str()), |
| 7803 | // End headers. |
| 7804 | MockRead("\r\n\r\n"), |
| 7805 | |
| 7806 | // Finally the tunnel is established. |
| 7807 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7808 | }; |
| 7809 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7810 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7811 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7812 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7813 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7814 | |
| 7815 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7816 | // request. |
| 7817 | TestCompletionCallback callback; |
| 7818 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7819 | int rv = callback.GetResult( |
| 7820 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7821 | |
| 7822 | EXPECT_THAT(rv, IsOk()); |
| 7823 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7824 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7825 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7826 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7827 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7828 | // Configure credentials and restart. The proxy responds with the challenge |
| 7829 | // message. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7830 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7831 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7832 | callback.callback())); |
| 7833 | EXPECT_THAT(rv, IsOk()); |
| 7834 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7835 | response = trans.GetResponseInfo(); |
| 7836 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7837 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7838 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7839 | // Restart once more. The tunnel will be established and then the SSL |
| 7840 | // handshake will reset. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7841 | rv = callback.GetResult( |
| 7842 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7843 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7844 | } |
| 7845 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7846 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7847 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7848 | // Test reading a server response which has only headers, and no body. |
| 7849 | // After some maximum number of bytes is consumed, the transaction should |
| 7850 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7851 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7852 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7853 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7854 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7855 | request.traffic_annotation = |
| 7856 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7857 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7860 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7861 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7862 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7863 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7864 | |
| 7865 | MockRead data_reads[] = { |
| 7866 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7867 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7868 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7869 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7870 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7871 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7872 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7874 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7875 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7876 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7878 | |
| 7879 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7880 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7881 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7882 | |
| 7883 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7884 | // establish tunnel. |
| 7885 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7886 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7887 | HttpRequestInfo request; |
| 7888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7889 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7890 | request.traffic_annotation = |
| 7891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7892 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7893 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7894 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7895 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7896 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7898 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7899 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7900 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7901 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7902 | // Since we have proxy, should try to establish tunnel. |
| 7903 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7904 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7905 | "Host: www.example.org:443\r\n" |
| 7906 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7907 | }; |
| 7908 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7909 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7910 | // connection. Usually a proxy would return 501 (not implemented), |
| 7911 | // or 200 (tunnel established). |
| 7912 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7913 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7914 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7915 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7916 | }; |
| 7917 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7918 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7919 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7921 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7923 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7925 | |
| 7926 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7927 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7928 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7929 | // Empty the current queue. This is necessary because idle sockets are |
| 7930 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7931 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7932 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7933 | // We now check to make sure the TCPClientSocket was not added back to |
| 7934 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7935 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7936 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7937 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7938 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7939 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7940 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7941 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7942 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7943 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7944 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7946 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7947 | request.traffic_annotation = |
| 7948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7949 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7953 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7954 | MockRead data_reads[] = { |
| 7955 | // A part of the response body is received with the response headers. |
| 7956 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7957 | // The rest of the response body is received in two parts. |
| 7958 | MockRead("lo"), |
| 7959 | MockRead(" world"), |
| 7960 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7961 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7962 | }; |
| 7963 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7964 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7965 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7967 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7968 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7969 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7971 | |
| 7972 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7975 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7976 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7977 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7978 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7979 | std::string status_line = response->headers->GetStatusLine(); |
| 7980 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7981 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7982 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7983 | |
| 7984 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7985 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7987 | EXPECT_EQ("hello world", response_data); |
| 7988 | |
| 7989 | // Empty the current queue. This is necessary because idle sockets are |
| 7990 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7991 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7992 | |
| 7993 | // 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] | 7994 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7995 | } |
| 7996 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7997 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7998 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7999 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8000 | HttpRequestInfo request; |
| 8001 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8002 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8003 | request.traffic_annotation = |
| 8004 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8005 | |
| 8006 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8007 | MockWrite( |
| 8008 | "GET / HTTP/1.1\r\n" |
| 8009 | "Host: www.example.org\r\n" |
| 8010 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | }; |
| 8012 | |
| 8013 | MockRead data_reads[] = { |
| 8014 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8015 | MockRead("Content-Length: 11\r\n\r\n"), |
| 8016 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8017 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8018 | }; |
| 8019 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8020 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8021 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8022 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8023 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8024 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8026 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8029 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8030 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8031 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8032 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8034 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8036 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8037 | ASSERT_TRUE(response); |
| 8038 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8039 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8040 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8041 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8042 | |
| 8043 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8044 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8045 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8046 | EXPECT_EQ("hello world", response_data); |
| 8047 | |
| 8048 | // Empty the current queue. This is necessary because idle sockets are |
| 8049 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8050 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8051 | |
| 8052 | // 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] | 8053 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8054 | } |
| 8055 | |
| 8056 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8057 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8058 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8059 | HttpRequestInfo request; |
| 8060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8061 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8062 | request.traffic_annotation = |
| 8063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8064 | |
| 8065 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8066 | MockWrite( |
| 8067 | "GET / HTTP/1.1\r\n" |
| 8068 | "Host: www.example.org\r\n" |
| 8069 | "Connection: keep-alive\r\n\r\n"), |
| 8070 | MockWrite( |
| 8071 | "GET / HTTP/1.1\r\n" |
| 8072 | "Host: www.example.org\r\n" |
| 8073 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8074 | }; |
| 8075 | |
| 8076 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8077 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8078 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8079 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8080 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8081 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8082 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8084 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8085 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8086 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8087 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8088 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8090 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8091 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8093 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8094 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8096 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8097 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8099 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8100 | |
| 8101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8102 | ASSERT_TRUE(response); |
| 8103 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8104 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8105 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8106 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8107 | |
| 8108 | std::string response_data; |
| 8109 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8111 | EXPECT_EQ("hello world", response_data); |
| 8112 | |
| 8113 | // Empty the current queue. This is necessary because idle sockets are |
| 8114 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8115 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8116 | |
| 8117 | // 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] | 8118 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8119 | |
| 8120 | // Now start the second transaction, which should reuse the previous socket. |
| 8121 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8122 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8123 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8124 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8125 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8126 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8128 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8129 | |
| 8130 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8131 | ASSERT_TRUE(response); |
| 8132 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8133 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8134 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8135 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8136 | |
| 8137 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8138 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8139 | EXPECT_EQ("hello world", response_data); |
| 8140 | |
| 8141 | // Empty the current queue. This is necessary because idle sockets are |
| 8142 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8143 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8144 | |
| 8145 | // 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] | 8146 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8147 | } |
| 8148 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8149 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8150 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8151 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8152 | HttpRequestInfo request; |
| 8153 | request.method = "GET"; |
| 8154 | request.url = GURL("http://www.example.org/"); |
| 8155 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8156 | request.traffic_annotation = |
| 8157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8158 | |
| 8159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8161 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8162 | |
| 8163 | MockRead data_reads[] = { |
| 8164 | // A part of the response body is received with the response headers. |
| 8165 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8166 | // The rest of the response body is received in two parts. |
| 8167 | MockRead("lo"), MockRead(" world"), |
| 8168 | MockRead("junk"), // Should not be read!! |
| 8169 | MockRead(SYNCHRONOUS, OK), |
| 8170 | }; |
| 8171 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8172 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8174 | |
| 8175 | TestCompletionCallback callback; |
| 8176 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8177 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8179 | |
| 8180 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8182 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8183 | ASSERT_TRUE(response); |
| 8184 | EXPECT_TRUE(response->headers); |
| 8185 | std::string status_line = response->headers->GetStatusLine(); |
| 8186 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8187 | |
| 8188 | // Make memory critical notification and ensure the transaction still has been |
| 8189 | // operating right. |
| 8190 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8191 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8192 | base::RunLoop().RunUntilIdle(); |
| 8193 | |
| 8194 | // Socket should not be flushed as long as it is not idle. |
| 8195 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8196 | |
| 8197 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8198 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8199 | EXPECT_THAT(rv, IsOk()); |
| 8200 | EXPECT_EQ("hello world", response_data); |
| 8201 | |
| 8202 | // Empty the current queue. This is necessary because idle sockets are |
| 8203 | // added to the connection pool asynchronously with a PostTask. |
| 8204 | base::RunLoop().RunUntilIdle(); |
| 8205 | |
| 8206 | // We now check to make sure the socket was added back to the pool. |
| 8207 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8208 | |
| 8209 | // Idle sockets should be flushed now. |
| 8210 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8211 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8212 | base::RunLoop().RunUntilIdle(); |
| 8213 | |
| 8214 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8215 | } |
| 8216 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8217 | // Disable idle socket closing on memory pressure. |
| 8218 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8219 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8220 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8221 | HttpRequestInfo request; |
| 8222 | request.method = "GET"; |
| 8223 | request.url = GURL("http://www.example.org/"); |
| 8224 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8225 | request.traffic_annotation = |
| 8226 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8227 | |
| 8228 | // Disable idle socket closing on memory pressure. |
| 8229 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8231 | |
| 8232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8233 | |
| 8234 | MockRead data_reads[] = { |
| 8235 | // A part of the response body is received with the response headers. |
| 8236 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8237 | // The rest of the response body is received in two parts. |
| 8238 | MockRead("lo"), MockRead(" world"), |
| 8239 | MockRead("junk"), // Should not be read!! |
| 8240 | MockRead(SYNCHRONOUS, OK), |
| 8241 | }; |
| 8242 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8243 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8244 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8245 | |
| 8246 | TestCompletionCallback callback; |
| 8247 | |
| 8248 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8250 | |
| 8251 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8252 | |
| 8253 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8254 | ASSERT_TRUE(response); |
| 8255 | EXPECT_TRUE(response->headers); |
| 8256 | std::string status_line = response->headers->GetStatusLine(); |
| 8257 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8258 | |
| 8259 | // Make memory critical notification and ensure the transaction still has been |
| 8260 | // operating right. |
| 8261 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8262 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8263 | base::RunLoop().RunUntilIdle(); |
| 8264 | |
| 8265 | // Socket should not be flushed as long as it is not idle. |
| 8266 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8267 | |
| 8268 | std::string response_data; |
| 8269 | rv = ReadTransaction(&trans, &response_data); |
| 8270 | EXPECT_THAT(rv, IsOk()); |
| 8271 | EXPECT_EQ("hello world", response_data); |
| 8272 | |
| 8273 | // Empty the current queue. This is necessary because idle sockets are |
| 8274 | // added to the connection pool asynchronously with a PostTask. |
| 8275 | base::RunLoop().RunUntilIdle(); |
| 8276 | |
| 8277 | // We now check to make sure the socket was added back to the pool. |
| 8278 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8279 | |
| 8280 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8281 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8282 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8283 | base::RunLoop().RunUntilIdle(); |
| 8284 | |
| 8285 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8286 | |
| 8287 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8288 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8289 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8290 | base::RunLoop().RunUntilIdle(); |
| 8291 | |
| 8292 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8293 | } |
| 8294 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8295 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8296 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8297 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8298 | HttpRequestInfo request; |
| 8299 | request.method = "GET"; |
| 8300 | request.url = GURL("https://www.example.org/"); |
| 8301 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8302 | request.traffic_annotation = |
| 8303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8304 | |
| 8305 | MockWrite data_writes[] = { |
| 8306 | MockWrite("GET / HTTP/1.1\r\n" |
| 8307 | "Host: www.example.org\r\n" |
| 8308 | "Connection: keep-alive\r\n\r\n"), |
| 8309 | }; |
| 8310 | |
| 8311 | MockRead data_reads[] = { |
| 8312 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8313 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8314 | |
| 8315 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8317 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8318 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8320 | |
| 8321 | TestCompletionCallback callback; |
| 8322 | |
| 8323 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8324 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8325 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8326 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8328 | |
| 8329 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8332 | ASSERT_TRUE(response); |
| 8333 | ASSERT_TRUE(response->headers); |
| 8334 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8335 | |
| 8336 | // Make memory critical notification and ensure the transaction still has been |
| 8337 | // operating right. |
| 8338 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8339 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8340 | base::RunLoop().RunUntilIdle(); |
| 8341 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8342 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8343 | |
| 8344 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8345 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8346 | EXPECT_THAT(rv, IsOk()); |
| 8347 | EXPECT_EQ("hello world", response_data); |
| 8348 | |
| 8349 | // Empty the current queue. This is necessary because idle sockets are |
| 8350 | // added to the connection pool asynchronously with a PostTask. |
| 8351 | base::RunLoop().RunUntilIdle(); |
| 8352 | |
| 8353 | // 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] | 8354 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8355 | |
| 8356 | // Make memory notification once again and ensure idle socket is closed. |
| 8357 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8358 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8359 | base::RunLoop().RunUntilIdle(); |
| 8360 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8361 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8362 | } |
| 8363 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8364 | // Make sure that we recycle a socket after a zero-length response. |
| 8365 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8366 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8367 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8369 | request.url = GURL( |
| 8370 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8371 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8372 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8373 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8374 | request.traffic_annotation = |
| 8375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8376 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8378 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8379 | MockRead data_reads[] = { |
| 8380 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8381 | "Content-Length: 0\r\n" |
| 8382 | "Content-Type: text/html\r\n\r\n"), |
| 8383 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8385 | }; |
| 8386 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8387 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8389 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8390 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8391 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8394 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8396 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8398 | |
| 8399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8401 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8402 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8403 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8404 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8405 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8406 | std::string status_line = response->headers->GetStatusLine(); |
| 8407 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8408 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8409 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8410 | |
| 8411 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8412 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8414 | EXPECT_EQ("", response_data); |
| 8415 | |
| 8416 | // Empty the current queue. This is necessary because idle sockets are |
| 8417 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8418 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8419 | |
| 8420 | // 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] | 8421 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8422 | } |
| 8423 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8424 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8425 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8426 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8427 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8428 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8429 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8430 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8431 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8432 | // after use. |
| 8433 | request[0].method = "GET"; |
| 8434 | request[0].url = GURL("http://www.google.com/"); |
| 8435 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8436 | request[0].traffic_annotation = |
| 8437 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8438 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8439 | // transaction 1. The first attempts fails when writing the POST data. |
| 8440 | // This causes the transaction to retry with a new socket. The second |
| 8441 | // attempt succeeds. |
| 8442 | request[1].method = "POST"; |
| 8443 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8444 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8445 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8446 | request[1].traffic_annotation = |
| 8447 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8448 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8450 | |
| 8451 | // The first socket is used for transaction 1 and the first attempt of |
| 8452 | // transaction 2. |
| 8453 | |
| 8454 | // The response of transaction 1. |
| 8455 | MockRead data_reads1[] = { |
| 8456 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8457 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8458 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8459 | }; |
| 8460 | // The mock write results of transaction 1 and the first attempt of |
| 8461 | // transaction 2. |
| 8462 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8463 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8464 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8465 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8466 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8467 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8468 | |
| 8469 | // The second socket is used for the second attempt of transaction 2. |
| 8470 | |
| 8471 | // The response of transaction 2. |
| 8472 | MockRead data_reads2[] = { |
| 8473 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8474 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8475 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8476 | }; |
| 8477 | // The mock write results of the second attempt of transaction 2. |
| 8478 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8479 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8480 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8481 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8482 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8483 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8484 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8485 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8486 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8487 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8488 | "hello world", "welcome" |
| 8489 | }; |
| 8490 | |
| 8491 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8492 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8494 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8495 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8496 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8498 | |
| 8499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8502 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8503 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8504 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8505 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8506 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8507 | |
| 8508 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8509 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8511 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8512 | } |
| 8513 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8514 | |
| 8515 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8516 | // 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] | 8517 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8518 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8519 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8520 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8521 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8522 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8523 | request.traffic_annotation = |
| 8524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8528 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8529 | // The password contains an escaped character -- for this test to pass it |
| 8530 | // will need to be unescaped by HttpNetworkTransaction. |
| 8531 | EXPECT_EQ("b%40r", request.url.password()); |
| 8532 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8533 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8534 | MockWrite( |
| 8535 | "GET / HTTP/1.1\r\n" |
| 8536 | "Host: www.example.org\r\n" |
| 8537 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8538 | }; |
| 8539 | |
| 8540 | MockRead data_reads1[] = { |
| 8541 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8542 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8543 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8544 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8545 | }; |
| 8546 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8547 | // After the challenge above, the transaction will be restarted using the |
| 8548 | // identity from the url (foo, b@r) to answer the challenge. |
| 8549 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8550 | MockWrite( |
| 8551 | "GET / HTTP/1.1\r\n" |
| 8552 | "Host: www.example.org\r\n" |
| 8553 | "Connection: keep-alive\r\n" |
| 8554 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8555 | }; |
| 8556 | |
| 8557 | MockRead data_reads2[] = { |
| 8558 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8559 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8560 | MockRead(SYNCHRONOUS, OK), |
| 8561 | }; |
| 8562 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8563 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8564 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8566 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8568 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8569 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8570 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8571 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8572 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8573 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8574 | |
| 8575 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8576 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8578 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8579 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8580 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8582 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8583 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8584 | |
| 8585 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8586 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8587 | |
| 8588 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8589 | |
| 8590 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8591 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8592 | } |
| 8593 | |
| 8594 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8595 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8596 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8597 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8598 | HttpRequestInfo request; |
| 8599 | request.method = "GET"; |
| 8600 | // Note: the URL has a username:password in it. The password "baz" is |
| 8601 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8602 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8603 | |
| 8604 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8605 | request.traffic_annotation = |
| 8606 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8607 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8610 | |
| 8611 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8612 | MockWrite( |
| 8613 | "GET / HTTP/1.1\r\n" |
| 8614 | "Host: www.example.org\r\n" |
| 8615 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8616 | }; |
| 8617 | |
| 8618 | MockRead data_reads1[] = { |
| 8619 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8620 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8621 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8622 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8623 | }; |
| 8624 | |
| 8625 | // After the challenge above, the transaction will be restarted using the |
| 8626 | // identity from the url (foo, baz) to answer the challenge. |
| 8627 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8628 | MockWrite( |
| 8629 | "GET / HTTP/1.1\r\n" |
| 8630 | "Host: www.example.org\r\n" |
| 8631 | "Connection: keep-alive\r\n" |
| 8632 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8633 | }; |
| 8634 | |
| 8635 | MockRead data_reads2[] = { |
| 8636 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8637 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8638 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8639 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8640 | }; |
| 8641 | |
| 8642 | // After the challenge above, the transaction will be restarted using the |
| 8643 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8644 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8645 | MockWrite( |
| 8646 | "GET / HTTP/1.1\r\n" |
| 8647 | "Host: www.example.org\r\n" |
| 8648 | "Connection: keep-alive\r\n" |
| 8649 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | }; |
| 8651 | |
| 8652 | MockRead data_reads3[] = { |
| 8653 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8654 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8655 | MockRead(SYNCHRONOUS, OK), |
| 8656 | }; |
| 8657 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8658 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8659 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8660 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8661 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8662 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8663 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8664 | |
| 8665 | TestCompletionCallback callback1; |
| 8666 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8667 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8668 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8669 | |
| 8670 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8671 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8673 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8674 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8675 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8677 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8678 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8679 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8681 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8682 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8683 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8684 | |
| 8685 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8686 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8688 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8689 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8690 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8692 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8693 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8694 | |
| 8695 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8696 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8697 | |
| 8698 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8699 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8700 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8701 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8702 | } |
| 8703 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8704 | |
| 8705 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8706 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8707 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8708 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8709 | HttpRequestInfo request; |
| 8710 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8711 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8712 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8713 | request.traffic_annotation = |
| 8714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8718 | |
| 8719 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8720 | MockWrite( |
| 8721 | "GET / HTTP/1.1\r\n" |
| 8722 | "Host: www.example.org\r\n" |
| 8723 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8724 | }; |
| 8725 | |
| 8726 | MockRead data_reads1[] = { |
| 8727 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8728 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8729 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8730 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8731 | }; |
| 8732 | |
| 8733 | // After the challenge above, the transaction will be restarted using the |
| 8734 | // identity supplied by the user, not the one in the URL, to answer the |
| 8735 | // challenge. |
| 8736 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8737 | MockWrite( |
| 8738 | "GET / HTTP/1.1\r\n" |
| 8739 | "Host: www.example.org\r\n" |
| 8740 | "Connection: keep-alive\r\n" |
| 8741 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8742 | }; |
| 8743 | |
| 8744 | MockRead data_reads3[] = { |
| 8745 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8746 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8747 | MockRead(SYNCHRONOUS, OK), |
| 8748 | }; |
| 8749 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8750 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8751 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8753 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8754 | |
| 8755 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8756 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8758 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8759 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8760 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8762 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8763 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8764 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8765 | |
| 8766 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8767 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8769 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8770 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8771 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8773 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8774 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8775 | |
| 8776 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8777 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8778 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8779 | |
| 8780 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8781 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8782 | } |
| 8783 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8784 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8785 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8787 | |
| 8788 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8789 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8790 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8792 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8793 | request.traffic_annotation = |
| 8794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8797 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8798 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8799 | MockWrite( |
| 8800 | "GET /x/y/z HTTP/1.1\r\n" |
| 8801 | "Host: www.example.org\r\n" |
| 8802 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8803 | }; |
| 8804 | |
| 8805 | MockRead data_reads1[] = { |
| 8806 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8807 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8808 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8809 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8810 | }; |
| 8811 | |
| 8812 | // Resend with authorization (username=foo, password=bar) |
| 8813 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8814 | MockWrite( |
| 8815 | "GET /x/y/z HTTP/1.1\r\n" |
| 8816 | "Host: www.example.org\r\n" |
| 8817 | "Connection: keep-alive\r\n" |
| 8818 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8819 | }; |
| 8820 | |
| 8821 | // Sever accepts the authorization. |
| 8822 | MockRead data_reads2[] = { |
| 8823 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8824 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | }; |
| 8827 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8828 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8829 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8830 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8831 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8833 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8834 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8835 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8837 | |
| 8838 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8839 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8841 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8842 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8843 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8845 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8847 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8848 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8850 | |
| 8851 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8852 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8853 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8854 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8855 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8856 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8857 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8858 | } |
| 8859 | |
| 8860 | // ------------------------------------------------------------------------ |
| 8861 | |
| 8862 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8863 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8864 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8865 | request.method = "GET"; |
| 8866 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8867 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8868 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8869 | request.traffic_annotation = |
| 8870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8872 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8873 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8874 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8875 | MockWrite( |
| 8876 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8877 | "Host: www.example.org\r\n" |
| 8878 | "Connection: keep-alive\r\n" |
| 8879 | // Send preemptive authorization for MyRealm1 |
| 8880 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8881 | }; |
| 8882 | |
| 8883 | // The server didn't like the preemptive authorization, and |
| 8884 | // challenges us for a different realm (MyRealm2). |
| 8885 | MockRead data_reads1[] = { |
| 8886 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8887 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8888 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8889 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8890 | }; |
| 8891 | |
| 8892 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8893 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8894 | MockWrite( |
| 8895 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8896 | "Host: www.example.org\r\n" |
| 8897 | "Connection: keep-alive\r\n" |
| 8898 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8899 | }; |
| 8900 | |
| 8901 | // Sever accepts the authorization. |
| 8902 | MockRead data_reads2[] = { |
| 8903 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8904 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8905 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8906 | }; |
| 8907 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8908 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8909 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8910 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8911 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8913 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8914 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8915 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8917 | |
| 8918 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8919 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8920 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8921 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8922 | ASSERT_TRUE(response); |
| 8923 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8924 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8925 | EXPECT_EQ("http://www.example.org", |
| 8926 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8927 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8928 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8930 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8932 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8933 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8935 | |
| 8936 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8937 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8939 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8940 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8941 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8942 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8943 | } |
| 8944 | |
| 8945 | // ------------------------------------------------------------------------ |
| 8946 | |
| 8947 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8948 | // succeed with preemptive authorization. |
| 8949 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8950 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8951 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8952 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8953 | request.traffic_annotation = |
| 8954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8957 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8958 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8959 | MockWrite( |
| 8960 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8961 | "Host: www.example.org\r\n" |
| 8962 | "Connection: keep-alive\r\n" |
| 8963 | // The authorization for MyRealm1 gets sent preemptively |
| 8964 | // (since the url is in the same protection space) |
| 8965 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8966 | }; |
| 8967 | |
| 8968 | // Sever accepts the preemptive authorization |
| 8969 | MockRead data_reads1[] = { |
| 8970 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8971 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8972 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8973 | }; |
| 8974 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8975 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8976 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8978 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8979 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8980 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8981 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8982 | |
| 8983 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8984 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8986 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8987 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8988 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8989 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8990 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8991 | } |
| 8992 | |
| 8993 | // ------------------------------------------------------------------------ |
| 8994 | |
| 8995 | // Transaction 4: request another URL in MyRealm (however the |
| 8996 | // url is not known to belong to the protection space, so no pre-auth). |
| 8997 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8998 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8999 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9000 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9001 | request.traffic_annotation = |
| 9002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9005 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9006 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9007 | MockWrite( |
| 9008 | "GET /x/1 HTTP/1.1\r\n" |
| 9009 | "Host: www.example.org\r\n" |
| 9010 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9011 | }; |
| 9012 | |
| 9013 | MockRead data_reads1[] = { |
| 9014 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9015 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9016 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9017 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9018 | }; |
| 9019 | |
| 9020 | // Resend with authorization from MyRealm's cache. |
| 9021 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9022 | MockWrite( |
| 9023 | "GET /x/1 HTTP/1.1\r\n" |
| 9024 | "Host: www.example.org\r\n" |
| 9025 | "Connection: keep-alive\r\n" |
| 9026 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9027 | }; |
| 9028 | |
| 9029 | // Sever accepts the authorization. |
| 9030 | MockRead data_reads2[] = { |
| 9031 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9032 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9033 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9034 | }; |
| 9035 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9036 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9037 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9038 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9039 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9041 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9043 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9045 | |
| 9046 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9049 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9050 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9051 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9053 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9054 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9055 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9057 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9058 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9059 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9060 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9061 | } |
| 9062 | |
| 9063 | // ------------------------------------------------------------------------ |
| 9064 | |
| 9065 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9066 | // cached identity. Should invalidate and re-prompt. |
| 9067 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9068 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9069 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9070 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9071 | request.traffic_annotation = |
| 9072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9075 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9076 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9077 | MockWrite( |
| 9078 | "GET /p/q/t HTTP/1.1\r\n" |
| 9079 | "Host: www.example.org\r\n" |
| 9080 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9081 | }; |
| 9082 | |
| 9083 | MockRead data_reads1[] = { |
| 9084 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9085 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9086 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9087 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9088 | }; |
| 9089 | |
| 9090 | // Resend with authorization from cache for MyRealm. |
| 9091 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9092 | MockWrite( |
| 9093 | "GET /p/q/t HTTP/1.1\r\n" |
| 9094 | "Host: www.example.org\r\n" |
| 9095 | "Connection: keep-alive\r\n" |
| 9096 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9097 | }; |
| 9098 | |
| 9099 | // Sever rejects the authorization. |
| 9100 | MockRead data_reads2[] = { |
| 9101 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9102 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9103 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9104 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9105 | }; |
| 9106 | |
| 9107 | // At this point we should prompt for new credentials for MyRealm. |
| 9108 | // Restart with username=foo3, password=foo4. |
| 9109 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9110 | MockWrite( |
| 9111 | "GET /p/q/t HTTP/1.1\r\n" |
| 9112 | "Host: www.example.org\r\n" |
| 9113 | "Connection: keep-alive\r\n" |
| 9114 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9115 | }; |
| 9116 | |
| 9117 | // Sever accepts the authorization. |
| 9118 | MockRead data_reads3[] = { |
| 9119 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9120 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9121 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9122 | }; |
| 9123 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9124 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9125 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9126 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9127 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9128 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9129 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9131 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9132 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9133 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9135 | |
| 9136 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9137 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9139 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9140 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9141 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9143 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9144 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9145 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9147 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9148 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9149 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9151 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9153 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9154 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9156 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9157 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9158 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9159 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9160 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9161 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9162 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9163 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9164 | } |
| 9165 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9166 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9167 | // Tests that nonce count increments when multiple auth attempts |
| 9168 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9169 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9170 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9171 | new HttpAuthHandlerDigest::Factory(); |
| 9172 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9173 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9174 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9175 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9177 | |
| 9178 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9179 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9180 | HttpRequestInfo request; |
| 9181 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9182 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9183 | request.traffic_annotation = |
| 9184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9186 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9187 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9188 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9189 | MockWrite( |
| 9190 | "GET /x/y/z HTTP/1.1\r\n" |
| 9191 | "Host: www.example.org\r\n" |
| 9192 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9193 | }; |
| 9194 | |
| 9195 | MockRead data_reads1[] = { |
| 9196 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9197 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9198 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9199 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9200 | }; |
| 9201 | |
| 9202 | // Resend with authorization (username=foo, password=bar) |
| 9203 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9204 | MockWrite( |
| 9205 | "GET /x/y/z HTTP/1.1\r\n" |
| 9206 | "Host: www.example.org\r\n" |
| 9207 | "Connection: keep-alive\r\n" |
| 9208 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9209 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9210 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9211 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9212 | }; |
| 9213 | |
| 9214 | // Sever accepts the authorization. |
| 9215 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9216 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9217 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | }; |
| 9219 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9220 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9221 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9222 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9223 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9225 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9227 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9229 | |
| 9230 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9231 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9233 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9234 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9235 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9237 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9239 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9240 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9242 | |
| 9243 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9246 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9247 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9248 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9249 | } |
| 9250 | |
| 9251 | // ------------------------------------------------------------------------ |
| 9252 | |
| 9253 | // Transaction 2: Request another resource in digestive's protection space. |
| 9254 | // This will preemptively add an Authorization header which should have an |
| 9255 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9256 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9257 | HttpRequestInfo request; |
| 9258 | request.method = "GET"; |
| 9259 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9260 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9261 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9262 | request.traffic_annotation = |
| 9263 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9264 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9265 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9266 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9267 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9268 | MockWrite( |
| 9269 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9270 | "Host: www.example.org\r\n" |
| 9271 | "Connection: keep-alive\r\n" |
| 9272 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9273 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9274 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9275 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9276 | }; |
| 9277 | |
| 9278 | // Sever accepts the authorization. |
| 9279 | MockRead data_reads1[] = { |
| 9280 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9281 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9282 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9283 | }; |
| 9284 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9285 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9286 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9288 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9290 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9292 | |
| 9293 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9294 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9296 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9297 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9298 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9299 | } |
| 9300 | } |
| 9301 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9302 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9303 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9304 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9307 | |
| 9308 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9309 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9310 | trans.read_buf_len_ = 15; |
| 9311 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9312 | |
| 9313 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9314 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9315 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9316 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9317 | response->response_time = base::Time::Now(); |
| 9318 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9319 | |
| 9320 | { // Setup state for response_.vary_data |
| 9321 | HttpRequestInfo request; |
| 9322 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9323 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9324 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9325 | request.extra_headers.SetHeader("Foo", "1"); |
| 9326 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9327 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9328 | } |
| 9329 | |
| 9330 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9331 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9332 | |
| 9333 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9334 | EXPECT_FALSE(trans.read_buf_); |
| 9335 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9336 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9337 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9338 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9339 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9340 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9341 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9342 | } |
| 9343 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9344 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9345 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9346 | HttpRequestInfo request; |
| 9347 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9348 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9349 | request.traffic_annotation = |
| 9350 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9354 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9355 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9356 | MockWrite( |
| 9357 | "GET / HTTP/1.1\r\n" |
| 9358 | "Host: www.example.org\r\n" |
| 9359 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9360 | }; |
| 9361 | |
| 9362 | MockRead data_reads[] = { |
| 9363 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9364 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9365 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9366 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9367 | }; |
| 9368 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9369 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9370 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9371 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9372 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9373 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9374 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9375 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9379 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9380 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9381 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9383 | |
| 9384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9385 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9387 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9389 | |
| 9390 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9393 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9394 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9395 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9396 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9397 | } |
| 9398 | |
| 9399 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9400 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9401 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9402 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9403 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9404 | |
| 9405 | HttpRequestInfo request; |
| 9406 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9407 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9408 | request.traffic_annotation = |
| 9409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9410 | |
| 9411 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9412 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9413 | "Host: www.example.org:443\r\n" |
| 9414 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9415 | }; |
| 9416 | |
| 9417 | MockRead proxy_reads[] = { |
| 9418 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9419 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9420 | }; |
| 9421 | |
| 9422 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9423 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9424 | "Host: www.example.org:443\r\n" |
| 9425 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9426 | MockWrite("GET / HTTP/1.1\r\n" |
| 9427 | "Host: www.example.org\r\n" |
| 9428 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9429 | }; |
| 9430 | |
| 9431 | MockRead data_reads[] = { |
| 9432 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9433 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9434 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9435 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9436 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9437 | }; |
| 9438 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9439 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9440 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9441 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9442 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9443 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9444 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9445 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9449 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9450 | |
| 9451 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9452 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9453 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9455 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9456 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9457 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9459 | |
| 9460 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9461 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9462 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9463 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9465 | |
| 9466 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9469 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9470 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9471 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9472 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9473 | } |
| 9474 | } |
| 9475 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9476 | |
| 9477 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9478 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9479 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9480 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9481 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9482 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9483 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9484 | |
| 9485 | HttpRequestInfo request; |
| 9486 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9487 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9488 | request.traffic_annotation = |
| 9489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9490 | |
| 9491 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9492 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9493 | "Host: www.example.org:443\r\n" |
| 9494 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9495 | MockWrite("GET / HTTP/1.1\r\n" |
| 9496 | "Host: www.example.org\r\n" |
| 9497 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9498 | }; |
| 9499 | |
| 9500 | MockRead data_reads[] = { |
| 9501 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9502 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9503 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9504 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9505 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9506 | }; |
| 9507 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9508 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9509 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9510 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9511 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9516 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9517 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9518 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9520 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9521 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9522 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9523 | |
| 9524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9525 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9526 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9527 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9528 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9529 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9530 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9531 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9532 | EXPECT_EQ(200, response->headers->response_code()); |
| 9533 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9534 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9535 | |
| 9536 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9537 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9538 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9539 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9540 | } |
| 9541 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9542 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9543 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9544 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9545 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9546 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9547 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9548 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9549 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9550 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9551 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9552 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9553 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9554 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9555 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9556 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9557 | request.traffic_annotation = |
| 9558 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9559 | |
| 9560 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9561 | MockWrite(ASYNC, 0, |
| 9562 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9563 | "Host: www.example.org:443\r\n" |
| 9564 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9565 | }; |
| 9566 | |
| 9567 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9568 | // Pause on first read. |
| 9569 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9570 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9571 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9572 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9573 | }; |
| 9574 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9575 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9576 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9577 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9578 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9581 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9585 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9586 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9588 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9589 | |
| 9590 | // Host resolution takes |kTimeIncrement|. |
| 9591 | FastForwardBy(kTimeIncrement); |
| 9592 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9593 | // request to instantly complete, and the async connect will start as well. |
| 9594 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9595 | |
| 9596 | // Connecting takes |kTimeIncrement|. |
| 9597 | FastForwardBy(kTimeIncrement); |
| 9598 | data.RunUntilPaused(); |
| 9599 | |
| 9600 | // The server takes |kTimeIncrement| to respond. |
| 9601 | FastForwardBy(kTimeIncrement); |
| 9602 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9603 | |
| 9604 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9605 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9606 | } |
| 9607 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9608 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9609 | TEST_F(HttpNetworkTransactionTest, |
| 9610 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9611 | base::HistogramTester histograms; |
| 9612 | session_deps_.proxy_resolution_service = |
| 9613 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9614 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9615 | TestNetLog net_log; |
| 9616 | session_deps_.net_log = &net_log; |
| 9617 | |
| 9618 | HttpRequestInfo request; |
| 9619 | request.method = "GET"; |
| 9620 | request.url = GURL("https://www.example.org/"); |
| 9621 | request.traffic_annotation = |
| 9622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9623 | |
| 9624 | MockWrite data_writes[] = { |
| 9625 | MockWrite(ASYNC, 0, |
| 9626 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9627 | "Host: www.example.org:443\r\n" |
| 9628 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9629 | }; |
| 9630 | |
| 9631 | MockRead data_reads[] = { |
| 9632 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9633 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9634 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9635 | }; |
| 9636 | |
| 9637 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9638 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9639 | |
| 9640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9642 | |
| 9643 | TestCompletionCallback callback; |
| 9644 | |
| 9645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9647 | |
| 9648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9650 | |
| 9651 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9652 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9653 | } |
| 9654 | |
| 9655 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9656 | // request for main frames. |
| 9657 | TEST_F(HttpNetworkTransactionTest, |
| 9658 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9659 | base::HistogramTester histograms; |
| 9660 | session_deps_.proxy_resolution_service = |
| 9661 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9662 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9663 | TestNetLog net_log; |
| 9664 | session_deps_.net_log = &net_log; |
| 9665 | |
| 9666 | HttpRequestInfo request; |
| 9667 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9668 | request.method = "GET"; |
| 9669 | request.url = GURL("https://www.example.org/"); |
| 9670 | request.traffic_annotation = |
| 9671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9672 | |
| 9673 | MockWrite data_writes[] = { |
| 9674 | MockWrite(ASYNC, 0, |
| 9675 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9676 | "Host: www.example.org:443\r\n" |
| 9677 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9678 | }; |
| 9679 | |
| 9680 | MockRead data_reads[] = { |
| 9681 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9682 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9683 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9684 | }; |
| 9685 | |
| 9686 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9687 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9688 | |
| 9689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9691 | |
| 9692 | TestCompletionCallback callback; |
| 9693 | |
| 9694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9696 | |
| 9697 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9699 | |
| 9700 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9701 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9702 | } |
| 9703 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9704 | // Tests that an HTTPS (SPDY) Proxy's cannot redirect a CONNECT request for main |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9705 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9706 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9707 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9708 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9709 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9710 | TestNetLog net_log; |
| 9711 | session_deps_.net_log = &net_log; |
| 9712 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9713 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9714 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9715 | |
| 9716 | HttpRequestInfo request; |
| 9717 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9718 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9719 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9720 | request.traffic_annotation = |
| 9721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9722 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9723 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9724 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9725 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9726 | spdy::SpdySerializedFrame goaway( |
| 9727 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9728 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9729 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9730 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9731 | }; |
| 9732 | |
| 9733 | static const char* const kExtraHeaders[] = { |
| 9734 | "location", |
| 9735 | "http://login.example.com/", |
| 9736 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9737 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9738 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9739 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9740 | // Pause on first read. |
| 9741 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9742 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9743 | }; |
| 9744 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9745 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9746 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9747 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9748 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9749 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9752 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9753 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9755 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9756 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9757 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9759 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9760 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9761 | // Host resolution takes |kTimeIncrement|. |
| 9762 | FastForwardBy(kTimeIncrement); |
| 9763 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9764 | // request to instantly complete, and the async connect will start as well. |
| 9765 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9766 | |
| 9767 | // Connecting takes |kTimeIncrement|. |
| 9768 | FastForwardBy(kTimeIncrement); |
| 9769 | data.RunUntilPaused(); |
| 9770 | |
| 9771 | FastForwardBy(kTimeIncrement); |
| 9772 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9773 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9774 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9775 | } |
| 9776 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9777 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9778 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9779 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9780 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9781 | |
| 9782 | HttpRequestInfo request; |
| 9783 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9784 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9785 | request.traffic_annotation = |
| 9786 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9787 | |
| 9788 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9789 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9790 | "Host: www.example.org:443\r\n" |
| 9791 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9792 | }; |
| 9793 | |
| 9794 | MockRead data_reads[] = { |
| 9795 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9796 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9797 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9798 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9799 | }; |
| 9800 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9801 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9802 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9803 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9804 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9807 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9814 | |
| 9815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9816 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9817 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9818 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9819 | } |
| 9820 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9821 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9822 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9823 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9824 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9825 | |
| 9826 | HttpRequestInfo request; |
| 9827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9828 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9829 | request.traffic_annotation = |
| 9830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9831 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9832 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9833 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9834 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9835 | spdy::SpdySerializedFrame rst( |
| 9836 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9837 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9838 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9839 | }; |
| 9840 | |
| 9841 | static const char* const kExtraHeaders[] = { |
| 9842 | "location", |
| 9843 | "http://login.example.com/", |
| 9844 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9845 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9846 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9847 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9848 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9849 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9850 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9851 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9852 | }; |
| 9853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9854 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9855 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9856 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9857 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9861 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9862 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9864 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9865 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9866 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9868 | |
| 9869 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9870 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9871 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9872 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9873 | } |
| 9874 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9875 | // Test the request-challenge-retry sequence for basic auth, through |
| 9876 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9877 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9878 | HttpRequestInfo request; |
| 9879 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9880 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9881 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9882 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9883 | request.traffic_annotation = |
| 9884 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9885 | |
| 9886 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9887 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9888 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9889 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9890 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9891 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9893 | |
| 9894 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9895 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9896 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9897 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9898 | spdy::SpdySerializedFrame rst( |
| 9899 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9900 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9902 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9903 | // be issuing -- the final header line contains the credentials. |
| 9904 | const char* const kAuthCredentials[] = { |
| 9905 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9906 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9907 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9908 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9909 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9910 | HostPortPair("www.example.org", 443))); |
| 9911 | // fetch https://www.example.org/ via HTTP |
| 9912 | const char get[] = |
| 9913 | "GET / HTTP/1.1\r\n" |
| 9914 | "Host: www.example.org\r\n" |
| 9915 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9916 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9917 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9918 | |
| 9919 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9920 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9921 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9922 | }; |
| 9923 | |
| 9924 | // The proxy responds to the connect with a 407, using a persistent |
| 9925 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9926 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9927 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9928 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9929 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9930 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9931 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9932 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9933 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 9934 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9935 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9936 | "Content-Length: 5\r\n\r\n"; |
| 9937 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9938 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9939 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9940 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9941 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9942 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9943 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9944 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9945 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9946 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9947 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9948 | }; |
| 9949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9950 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9951 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9952 | // Negotiate SPDY to the proxy |
| 9953 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9954 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9956 | // Vanilla SSL to the server |
| 9957 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9958 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9959 | |
| 9960 | TestCompletionCallback callback1; |
| 9961 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9962 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9963 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9964 | |
| 9965 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9966 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9967 | |
| 9968 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9969 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9970 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9971 | log.GetEntries(&entries); |
| 9972 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9973 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9974 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9975 | ExpectLogContainsSomewhere( |
| 9976 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9977 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9978 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9979 | |
| 9980 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9981 | ASSERT_TRUE(response); |
| 9982 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9983 | EXPECT_EQ(407, response->headers->response_code()); |
| 9984 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9985 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 9986 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9987 | |
| 9988 | TestCompletionCallback callback2; |
| 9989 | |
| 9990 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9991 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9993 | |
| 9994 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9996 | |
| 9997 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9998 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9999 | |
| 10000 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10001 | EXPECT_EQ(200, response->headers->response_code()); |
| 10002 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10003 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10004 | |
| 10005 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10006 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10007 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10008 | LoadTimingInfo load_timing_info; |
| 10009 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10010 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10011 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10012 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10013 | trans.reset(); |
| 10014 | session->CloseAllConnections(); |
| 10015 | } |
| 10016 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10017 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10018 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10019 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10020 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10021 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10022 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10023 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10024 | HttpRequestInfo request; |
| 10025 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10026 | request.traffic_annotation = |
| 10027 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10028 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10030 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10031 | push_request.method = "GET"; |
| 10032 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10033 | push_request.traffic_annotation = |
| 10034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10035 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10036 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10037 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10038 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10039 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10040 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10041 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10042 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10043 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10044 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10045 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10046 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10047 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10048 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10049 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10050 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10051 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10052 | |
| 10053 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10054 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10055 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10056 | }; |
| 10057 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10058 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10059 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10060 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10061 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10062 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10063 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10064 | spdy::SpdySerializedFrame stream1_body( |
| 10065 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10066 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10067 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10068 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10069 | |
| 10070 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10071 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10072 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10073 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10074 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10075 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10076 | }; |
| 10077 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10078 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10079 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10080 | // Negotiate SPDY to the proxy |
| 10081 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10082 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10084 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10085 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10086 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10087 | TestCompletionCallback callback; |
| 10088 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10090 | |
| 10091 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10092 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10093 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10094 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10095 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10096 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10097 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10099 | |
| 10100 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10101 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10102 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10103 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10104 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10105 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10106 | |
| 10107 | EXPECT_EQ(200, response->headers->response_code()); |
| 10108 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10109 | |
| 10110 | std::string response_data; |
| 10111 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10112 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10113 | EXPECT_EQ("hello!", response_data); |
| 10114 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10115 | LoadTimingInfo load_timing_info; |
| 10116 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10117 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10118 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10119 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10120 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10121 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10122 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10123 | |
| 10124 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10125 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10126 | EXPECT_EQ("pushed", response_data); |
| 10127 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10128 | LoadTimingInfo push_load_timing_info; |
| 10129 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10130 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10131 | // The transactions should share a socket ID, despite being for different |
| 10132 | // origins. |
| 10133 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10134 | push_load_timing_info.socket_log_id); |
| 10135 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10136 | trans.reset(); |
| 10137 | push_trans.reset(); |
| 10138 | session->CloseAllConnections(); |
| 10139 | } |
| 10140 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10141 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10142 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10143 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10144 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10145 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10146 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10147 | HttpRequestInfo request; |
| 10148 | |
| 10149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10150 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10151 | request.traffic_annotation = |
| 10152 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10153 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10154 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10155 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10156 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10157 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10158 | |
| 10159 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10160 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10161 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10162 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10164 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10165 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10166 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10167 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10168 | spdy::SpdySerializedFrame push_rst( |
| 10169 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10170 | |
| 10171 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10172 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10173 | }; |
| 10174 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10175 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10176 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10177 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10178 | spdy::SpdySerializedFrame stream1_body( |
| 10179 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10180 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10181 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10182 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10183 | |
| 10184 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10185 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10186 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10187 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10188 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10189 | }; |
| 10190 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10191 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10192 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10193 | // Negotiate SPDY to the proxy |
| 10194 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10195 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10197 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10198 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10199 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10200 | TestCompletionCallback callback; |
| 10201 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10203 | |
| 10204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10206 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10207 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10208 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10209 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10210 | |
| 10211 | EXPECT_EQ(200, response->headers->response_code()); |
| 10212 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10213 | |
| 10214 | std::string response_data; |
| 10215 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10217 | EXPECT_EQ("hello!", response_data); |
| 10218 | |
| 10219 | trans.reset(); |
| 10220 | session->CloseAllConnections(); |
| 10221 | } |
| 10222 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10223 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10224 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10225 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10226 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10227 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10228 | proxy_delegate->set_trusted_spdy_proxy( |
| 10229 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10230 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10231 | HttpRequestInfo request; |
| 10232 | |
| 10233 | request.method = "GET"; |
| 10234 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10235 | request.traffic_annotation = |
| 10236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10237 | |
| 10238 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10239 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10240 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10241 | BoundTestNetLog log; |
| 10242 | session_deps_.net_log = log.bound().net_log(); |
| 10243 | |
| 10244 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10245 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10246 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10247 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10248 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10249 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10250 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10251 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10252 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10253 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10254 | |
| 10255 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10256 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10257 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10258 | }; |
| 10259 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10260 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10261 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10262 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10263 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10264 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10265 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10266 | spdy::SpdySerializedFrame stream1_body( |
| 10267 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10268 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10269 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10270 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10271 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10272 | spdy::SpdySerializedFrame stream2_body( |
| 10273 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10274 | |
| 10275 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10276 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10277 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10278 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10279 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10280 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10281 | }; |
| 10282 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10283 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10284 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10285 | // Negotiate SPDY to the proxy |
| 10286 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10287 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10289 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10290 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10291 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10292 | TestCompletionCallback callback; |
| 10293 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10295 | |
| 10296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10297 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10298 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10299 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10300 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10301 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10302 | |
| 10303 | EXPECT_EQ(200, response->headers->response_code()); |
| 10304 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10305 | |
| 10306 | std::string response_data; |
| 10307 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10308 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10309 | EXPECT_EQ("hello!", response_data); |
| 10310 | |
| 10311 | trans.reset(); |
| 10312 | session->CloseAllConnections(); |
| 10313 | } |
| 10314 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10315 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10316 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10317 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10318 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10319 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10320 | |
| 10321 | HttpRequestInfo request; |
| 10322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10323 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10324 | request.traffic_annotation = |
| 10325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10326 | |
| 10327 | // Attempt to fetch the URL from a server with a bad cert |
| 10328 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10329 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10330 | "Host: www.example.org:443\r\n" |
| 10331 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10332 | }; |
| 10333 | |
| 10334 | MockRead bad_cert_reads[] = { |
| 10335 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10336 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10337 | }; |
| 10338 | |
| 10339 | // Attempt to fetch the URL with a good cert |
| 10340 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10341 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10342 | "Host: www.example.org:443\r\n" |
| 10343 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10344 | MockWrite("GET / HTTP/1.1\r\n" |
| 10345 | "Host: www.example.org\r\n" |
| 10346 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10347 | }; |
| 10348 | |
| 10349 | MockRead good_cert_reads[] = { |
| 10350 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10351 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10352 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10353 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10354 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10355 | }; |
| 10356 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10357 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10358 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10359 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10360 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10361 | |
| 10362 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10364 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10366 | |
| 10367 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10372 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10373 | |
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] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10376 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10377 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10379 | |
| 10380 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10381 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10383 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10385 | |
| 10386 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10387 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10389 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10390 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10391 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10392 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10393 | } |
| 10394 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10395 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10396 | HttpRequestInfo request; |
| 10397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10398 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10399 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10400 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10401 | request.traffic_annotation = |
| 10402 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10403 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10404 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10406 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10407 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10408 | MockWrite( |
| 10409 | "GET / HTTP/1.1\r\n" |
| 10410 | "Host: www.example.org\r\n" |
| 10411 | "Connection: keep-alive\r\n" |
| 10412 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10413 | }; |
| 10414 | |
| 10415 | // Lastly, the server responds with the actual content. |
| 10416 | MockRead data_reads[] = { |
| 10417 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10418 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10419 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10420 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10421 | }; |
| 10422 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10423 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10426 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10427 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10428 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10430 | |
| 10431 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10432 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10433 | } |
| 10434 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10435 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10436 | // Test user agent values, used both for the request header of the original |
| 10437 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10438 | // no request header / no HttpUserAgentSettings object. |
| 10439 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10440 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10441 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10442 | if (!setting_user_agent) { |
| 10443 | session_deps_.http_user_agent_settings.reset(); |
| 10444 | } else { |
| 10445 | session_deps_.http_user_agent_settings = |
| 10446 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10447 | std::string() /* accept-language */, setting_user_agent); |
| 10448 | } |
| 10449 | session_deps_.proxy_resolution_service = |
| 10450 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10451 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10452 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10453 | for (const char* request_user_agent : kTestUserAgents) { |
| 10454 | HttpRequestInfo request; |
| 10455 | request.method = "GET"; |
| 10456 | request.url = GURL("https://www.example.org/"); |
| 10457 | if (request_user_agent) { |
| 10458 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10459 | request_user_agent); |
| 10460 | } |
| 10461 | request.traffic_annotation = |
| 10462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10463 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10465 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10466 | std::string expected_request; |
| 10467 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10468 | expected_request = |
| 10469 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10470 | "Host: www.example.org:443\r\n" |
| 10471 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10472 | } else { |
| 10473 | expected_request = base::StringPrintf( |
| 10474 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10475 | "Host: www.example.org:443\r\n" |
| 10476 | "Proxy-Connection: keep-alive\r\n" |
| 10477 | "User-Agent: %s\r\n\r\n", |
| 10478 | setting_user_agent); |
| 10479 | } |
| 10480 | MockWrite data_writes[] = { |
| 10481 | MockWrite(expected_request.c_str()), |
| 10482 | }; |
| 10483 | MockRead data_reads[] = { |
| 10484 | // Return an error, so the transaction stops here (this test isn't |
| 10485 | // interested in the rest). |
| 10486 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10487 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10488 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10489 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10490 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10491 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10492 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10493 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10494 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10495 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10496 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10498 | |
| 10499 | rv = callback.WaitForResult(); |
| 10500 | EXPECT_THAT(rv, IsOk()); |
| 10501 | } |
| 10502 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10503 | } |
| 10504 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10505 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10506 | HttpRequestInfo request; |
| 10507 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10508 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10509 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10510 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10511 | request.traffic_annotation = |
| 10512 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10513 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10515 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10516 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10517 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10518 | MockWrite( |
| 10519 | "GET / HTTP/1.1\r\n" |
| 10520 | "Host: www.example.org\r\n" |
| 10521 | "Connection: keep-alive\r\n" |
| 10522 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10523 | }; |
| 10524 | |
| 10525 | // Lastly, the server responds with the actual content. |
| 10526 | MockRead data_reads[] = { |
| 10527 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10528 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10529 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10530 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10531 | }; |
| 10532 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10533 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10536 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10537 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10538 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10540 | |
| 10541 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10542 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10543 | } |
| 10544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10545 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10546 | HttpRequestInfo request; |
| 10547 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10548 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10549 | request.traffic_annotation = |
| 10550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10554 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10555 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10556 | MockWrite( |
| 10557 | "POST / HTTP/1.1\r\n" |
| 10558 | "Host: www.example.org\r\n" |
| 10559 | "Connection: keep-alive\r\n" |
| 10560 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10561 | }; |
| 10562 | |
| 10563 | // Lastly, the server responds with the actual content. |
| 10564 | MockRead data_reads[] = { |
| 10565 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10566 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10567 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10568 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10569 | }; |
| 10570 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10571 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10574 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10578 | |
| 10579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10580 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10581 | } |
| 10582 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10583 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10584 | HttpRequestInfo request; |
| 10585 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10586 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10587 | request.traffic_annotation = |
| 10588 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10589 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10590 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10592 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10593 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10594 | MockWrite( |
| 10595 | "PUT / HTTP/1.1\r\n" |
| 10596 | "Host: www.example.org\r\n" |
| 10597 | "Connection: keep-alive\r\n" |
| 10598 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10599 | }; |
| 10600 | |
| 10601 | // Lastly, the server responds with the actual content. |
| 10602 | MockRead data_reads[] = { |
| 10603 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10604 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10605 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10606 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10607 | }; |
| 10608 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10609 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10612 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10616 | |
| 10617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10619 | } |
| 10620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10621 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10622 | HttpRequestInfo request; |
| 10623 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10624 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10625 | request.traffic_annotation = |
| 10626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10629 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10630 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10631 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10632 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10633 | "Host: www.example.org\r\n" |
| 10634 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10635 | }; |
| 10636 | |
| 10637 | // Lastly, the server responds with the actual content. |
| 10638 | MockRead data_reads[] = { |
| 10639 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10640 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10641 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10642 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10643 | }; |
| 10644 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10645 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10646 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10648 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10650 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10652 | |
| 10653 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10654 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10655 | } |
| 10656 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10657 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10658 | HttpRequestInfo request; |
| 10659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10660 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10661 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10662 | request.traffic_annotation = |
| 10663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10664 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10667 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10668 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10669 | MockWrite( |
| 10670 | "GET / HTTP/1.1\r\n" |
| 10671 | "Host: www.example.org\r\n" |
| 10672 | "Connection: keep-alive\r\n" |
| 10673 | "Pragma: no-cache\r\n" |
| 10674 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10675 | }; |
| 10676 | |
| 10677 | // Lastly, the server responds with the actual content. |
| 10678 | MockRead data_reads[] = { |
| 10679 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10680 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10681 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10682 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10683 | }; |
| 10684 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10685 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10686 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10688 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10689 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10690 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10691 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10692 | |
| 10693 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10694 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10695 | } |
| 10696 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10697 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10698 | HttpRequestInfo request; |
| 10699 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10700 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10701 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10702 | request.traffic_annotation = |
| 10703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10704 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10707 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10708 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10709 | MockWrite( |
| 10710 | "GET / HTTP/1.1\r\n" |
| 10711 | "Host: www.example.org\r\n" |
| 10712 | "Connection: keep-alive\r\n" |
| 10713 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10714 | }; |
| 10715 | |
| 10716 | // Lastly, the server responds with the actual content. |
| 10717 | MockRead data_reads[] = { |
| 10718 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10719 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10720 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10721 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10722 | }; |
| 10723 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10724 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10725 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10727 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10728 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10729 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10731 | |
| 10732 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10733 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10734 | } |
| 10735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10736 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10737 | HttpRequestInfo request; |
| 10738 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10739 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10740 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10741 | request.traffic_annotation = |
| 10742 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10743 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10745 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10746 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10747 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10748 | MockWrite( |
| 10749 | "GET / HTTP/1.1\r\n" |
| 10750 | "Host: www.example.org\r\n" |
| 10751 | "Connection: keep-alive\r\n" |
| 10752 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10753 | }; |
| 10754 | |
| 10755 | // Lastly, the server responds with the actual content. |
| 10756 | MockRead data_reads[] = { |
| 10757 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10758 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10759 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10760 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10761 | }; |
| 10762 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10763 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10764 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10766 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10767 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10768 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10770 | |
| 10771 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10772 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10773 | } |
| 10774 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10775 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10776 | HttpRequestInfo request; |
| 10777 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10778 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10779 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10780 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10781 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10782 | request.traffic_annotation = |
| 10783 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10784 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10786 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10787 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10788 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10789 | MockWrite( |
| 10790 | "GET / HTTP/1.1\r\n" |
| 10791 | "Host: www.example.org\r\n" |
| 10792 | "Connection: keep-alive\r\n" |
| 10793 | "referer: www.foo.com\r\n" |
| 10794 | "hEllo: Kitty\r\n" |
| 10795 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10796 | }; |
| 10797 | |
| 10798 | // Lastly, the server responds with the actual content. |
| 10799 | MockRead data_reads[] = { |
| 10800 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10801 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10802 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10804 | }; |
| 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] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10809 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10811 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10813 | |
| 10814 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10815 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10816 | } |
| 10817 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10818 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10819 | HttpRequestInfo request; |
| 10820 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10821 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10822 | request.traffic_annotation = |
| 10823 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10824 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10825 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10826 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10827 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10828 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10829 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10830 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10833 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10834 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10835 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10836 | |
| 10837 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10838 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10839 | MockWrite("GET / HTTP/1.1\r\n" |
| 10840 | "Host: www.example.org\r\n" |
| 10841 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10842 | |
| 10843 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10844 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10845 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10846 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10847 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10848 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10849 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10850 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10852 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10853 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10854 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10855 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10856 | |
| 10857 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10858 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10860 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10861 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10862 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10863 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10864 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10865 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10866 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10867 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10868 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10869 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10870 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10871 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10872 | EXPECT_EQ("Payload", response_text); |
| 10873 | } |
| 10874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10875 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10876 | HttpRequestInfo request; |
| 10877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10878 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10879 | request.traffic_annotation = |
| 10880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10881 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10882 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10883 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10884 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10885 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10886 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10890 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10891 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10892 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10893 | |
| 10894 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10895 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10896 | base::size(write_buffer)), |
| 10897 | MockWrite("GET / HTTP/1.1\r\n" |
| 10898 | "Host: www.example.org\r\n" |
| 10899 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10900 | |
| 10901 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10902 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10903 | base::size(read_buffer)), |
| 10904 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10905 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10906 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10907 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10908 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10909 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10910 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10911 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10914 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10915 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10916 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10918 | |
| 10919 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10921 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10922 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10923 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10924 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10925 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10927 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10928 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10929 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10930 | |
| 10931 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10932 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10933 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10934 | EXPECT_EQ("Payload", response_text); |
| 10935 | } |
| 10936 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10937 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10938 | HttpRequestInfo request; |
| 10939 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10940 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10941 | request.traffic_annotation = |
| 10942 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10943 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10944 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10945 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10946 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10947 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10951 | |
| 10952 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10953 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10954 | |
| 10955 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10956 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10957 | MockWrite("GET / HTTP/1.1\r\n" |
| 10958 | "Host: www.example.org\r\n" |
| 10959 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10960 | |
| 10961 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10962 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10963 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10964 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10965 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10966 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10967 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10968 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10969 | |
| 10970 | TestCompletionCallback callback; |
| 10971 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10972 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10974 | |
| 10975 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10978 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10979 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10980 | |
| 10981 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10982 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10983 | TestLoadTimingNotReused(load_timing_info, |
| 10984 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10985 | |
| 10986 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10987 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10988 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10989 | EXPECT_EQ("Payload", response_text); |
| 10990 | } |
| 10991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10992 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10993 | HttpRequestInfo request; |
| 10994 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10995 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10996 | request.traffic_annotation = |
| 10997 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10998 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10999 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11000 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11001 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11002 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11003 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11006 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11007 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11008 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11009 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11010 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11011 | 0x05, // Version |
| 11012 | 0x01, // Command (CONNECT) |
| 11013 | 0x00, // Reserved. |
| 11014 | 0x03, // Address type (DOMAINNAME). |
| 11015 | 0x0F, // Length of domain (15) |
| 11016 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11017 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11018 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11019 | const char kSOCKS5OkResponse[] = |
| 11020 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11021 | |
| 11022 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11023 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11024 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11025 | MockWrite("GET / HTTP/1.1\r\n" |
| 11026 | "Host: www.example.org\r\n" |
| 11027 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11028 | |
| 11029 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11030 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11031 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11032 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11033 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11034 | MockRead("Payload"), |
| 11035 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11036 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11037 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11040 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11041 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11042 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11044 | |
| 11045 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11046 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11049 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11050 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11051 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11052 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11053 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11054 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11055 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11056 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11057 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11058 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11060 | EXPECT_EQ("Payload", response_text); |
| 11061 | } |
| 11062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11063 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11064 | HttpRequestInfo request; |
| 11065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11066 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11067 | request.traffic_annotation = |
| 11068 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11069 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11070 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11071 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11072 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11073 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11074 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11075 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11078 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11079 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11080 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11081 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11082 | 0x05, // Version |
| 11083 | 0x01, // Command (CONNECT) |
| 11084 | 0x00, // Reserved. |
| 11085 | 0x03, // Address type (DOMAINNAME). |
| 11086 | 0x0F, // Length of domain (15) |
| 11087 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11088 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11089 | }; |
| 11090 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11091 | const char kSOCKS5OkResponse[] = |
| 11092 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11093 | |
| 11094 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11095 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11096 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11097 | base::size(kSOCKS5OkRequest)), |
| 11098 | MockWrite("GET / HTTP/1.1\r\n" |
| 11099 | "Host: www.example.org\r\n" |
| 11100 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11101 | |
| 11102 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11103 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11104 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11105 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11106 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11107 | MockRead("Payload"), |
| 11108 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11109 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11110 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11112 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11113 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11116 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11117 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11118 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11120 | |
| 11121 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11122 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11124 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11125 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11126 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11127 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11128 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11129 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11130 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11131 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11132 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11133 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11134 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11136 | EXPECT_EQ("Payload", response_text); |
| 11137 | } |
| 11138 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11139 | namespace { |
| 11140 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11141 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11142 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11143 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11144 | std::string proxy_server; |
| 11145 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11146 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11147 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11148 | }; |
| 11149 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11150 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11151 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11152 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11153 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11154 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11155 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11156 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11157 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11158 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11159 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11160 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11161 | |
| 11162 | return session; |
| 11163 | } |
| 11164 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11165 | int GroupIdTransactionHelper(const std::string& url, |
| 11166 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11167 | HttpRequestInfo request; |
| 11168 | request.method = "GET"; |
| 11169 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11170 | request.traffic_annotation = |
| 11171 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11175 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11176 | |
| 11177 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11178 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11179 | } |
| 11180 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11181 | } // namespace |
| 11182 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11183 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11184 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11185 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11186 | "", // unused |
| 11187 | "http://www.example.org/direct", |
| 11188 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11189 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11190 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11191 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11192 | }, |
| 11193 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11194 | "", // unused |
| 11195 | "http://[2001:1418:13:1::25]/direct", |
| 11196 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11197 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11198 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11199 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11200 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11201 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11202 | // SSL Tests |
| 11203 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11204 | "", // unused |
| 11205 | "https://www.example.org/direct_ssl", |
| 11206 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11207 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11208 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11209 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11210 | }, |
| 11211 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11212 | "", // unused |
| 11213 | "https://[2001:1418:13:1::25]/direct", |
| 11214 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11215 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11216 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11217 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11218 | }, |
| 11219 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11220 | "", // unused |
| 11221 | "https://host.with.alternate/direct", |
| 11222 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11223 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11224 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11225 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11226 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11227 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11228 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11229 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11230 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11231 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11232 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11233 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11234 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11235 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11236 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11237 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11238 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11239 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11240 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11241 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11242 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11243 | |
| 11244 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11245 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11246 | EXPECT_EQ(tests[i].expected_group_id, |
| 11247 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11248 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11249 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11250 | } |
| 11251 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11252 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11253 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11254 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11255 | "http_proxy", |
| 11256 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11257 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11258 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11259 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11260 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11261 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11262 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11263 | // SSL Tests |
| 11264 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11265 | "http_proxy", |
| 11266 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11267 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11268 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11269 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11270 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11271 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11272 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11273 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11274 | "http_proxy", |
| 11275 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11276 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11277 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11278 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11279 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11280 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11281 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11282 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11283 | "http_proxy", |
| 11284 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11285 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11286 | ClientSocketPool::SocketType::kFtp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11287 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11288 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11289 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11290 | }; |
| 11291 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11292 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11293 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11294 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11295 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11296 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11297 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11298 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11299 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11300 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11301 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11302 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11303 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11304 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11305 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11306 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11307 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11308 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11309 | |
| 11310 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11311 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11312 | EXPECT_EQ(tests[i].expected_group_id, |
| 11313 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11314 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11315 | } |
| 11316 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11317 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11318 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11319 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11320 | "socks4://socks_proxy:1080", |
| 11321 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11322 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11323 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11324 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11325 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11326 | }, |
| 11327 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11328 | "socks5://socks_proxy:1080", |
| 11329 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11330 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11331 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11332 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11333 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11334 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11336 | // SSL Tests |
| 11337 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11338 | "socks4://socks_proxy:1080", |
| 11339 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11340 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11341 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11342 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11343 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11344 | }, |
| 11345 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11346 | "socks5://socks_proxy:1080", |
| 11347 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11348 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11349 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11350 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11351 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11352 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11353 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11354 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11355 | "socks4://socks_proxy:1080", |
| 11356 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11357 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11358 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11359 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11360 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11361 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11362 | }; |
| 11363 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11364 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11365 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11366 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11367 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11368 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11369 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11370 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11371 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11372 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11373 | ProxyServer proxy_server( |
| 11374 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11375 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11376 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11377 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11378 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11379 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11380 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11381 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11383 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11384 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11385 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11386 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11387 | EXPECT_EQ(tests[i].expected_group_id, |
| 11388 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11389 | } |
| 11390 | } |
| 11391 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11392 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11393 | HttpRequestInfo request; |
| 11394 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11395 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11396 | request.traffic_annotation = |
| 11397 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11398 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11399 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11400 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11401 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11402 | // This simulates failure resolving all hostnames; that means we will fail |
| 11403 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11404 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11405 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11406 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11407 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11409 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11410 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11411 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11413 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11414 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11415 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11416 | } |
| 11417 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11418 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11419 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11420 | HttpRequestInfo request; |
| 11421 | request.method = "GET"; |
| 11422 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11423 | request.traffic_annotation = |
| 11424 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11425 | |
| 11426 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11427 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11428 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11429 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11430 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11433 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11437 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11439 | |
| 11440 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11441 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11442 | |
| 11443 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11444 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11445 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11446 | } |
| 11447 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11448 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11449 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11450 | HttpRequestInfo request; |
| 11451 | request.method = "GET"; |
| 11452 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11453 | request.traffic_annotation = |
| 11454 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11455 | |
| 11456 | MockRead data_reads[] = { |
| 11457 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11458 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11459 | }; |
| 11460 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11461 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11462 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11465 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11469 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11471 | |
| 11472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11473 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11475 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11476 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11477 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11478 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11479 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11480 | |
| 11481 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11482 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11483 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11484 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11485 | |
| 11486 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11487 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11488 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11489 | } |
| 11490 | |
| 11491 | // Make sure that a dropped connection while draining the body for auth |
| 11492 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11493 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11494 | HttpRequestInfo request; |
| 11495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11496 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11497 | request.traffic_annotation = |
| 11498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11499 | |
| 11500 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11501 | MockWrite( |
| 11502 | "GET / HTTP/1.1\r\n" |
| 11503 | "Host: www.example.org\r\n" |
| 11504 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11505 | }; |
| 11506 | |
| 11507 | MockRead data_reads1[] = { |
| 11508 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11509 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11510 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11511 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11512 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11513 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11514 | }; |
| 11515 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11516 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11517 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11519 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11520 | // be issuing -- the final header line contains the credentials. |
| 11521 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11522 | MockWrite( |
| 11523 | "GET / HTTP/1.1\r\n" |
| 11524 | "Host: www.example.org\r\n" |
| 11525 | "Connection: keep-alive\r\n" |
| 11526 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11527 | }; |
| 11528 | |
| 11529 | // Lastly, the server responds with the actual content. |
| 11530 | MockRead data_reads2[] = { |
| 11531 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11532 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11533 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11534 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11535 | }; |
| 11536 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11537 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11538 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11539 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11541 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11543 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11545 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11547 | |
| 11548 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11549 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11552 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11553 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11554 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11555 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11557 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11559 | |
| 11560 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11561 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11563 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11564 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11565 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11566 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11567 | } |
| 11568 | |
| 11569 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11570 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11571 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11572 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11573 | |
| 11574 | HttpRequestInfo request; |
| 11575 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11576 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11577 | request.traffic_annotation = |
| 11578 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11579 | |
| 11580 | MockRead proxy_reads[] = { |
| 11581 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11582 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11583 | }; |
| 11584 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11585 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11586 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11587 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11588 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11589 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11591 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11592 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11593 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11594 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11600 | |
| 11601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11602 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11603 | } |
| 11604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11605 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11606 | HttpRequestInfo request; |
| 11607 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11608 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11609 | request.traffic_annotation = |
| 11610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11611 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11614 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11615 | MockRead data_reads[] = { |
| 11616 | 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] | 11617 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11618 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11619 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11620 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11623 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11625 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11627 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11628 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11630 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11631 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11632 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11633 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11634 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11635 | |
| 11636 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11637 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11638 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11639 | } |
| 11640 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11641 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11642 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11643 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11644 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11645 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11646 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11648 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11649 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11650 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11651 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11652 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11653 | |
| 11654 | HttpRequestInfo request; |
| 11655 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11656 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11657 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11658 | request.traffic_annotation = |
| 11659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11663 | |
| 11664 | MockRead data_reads[] = { |
| 11665 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11666 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11667 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11668 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11669 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11672 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11674 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11676 | |
| 11677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11678 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11680 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11681 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11682 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11683 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11684 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11685 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11686 | } |
| 11687 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11688 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11689 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11690 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11691 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11692 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11693 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11694 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11695 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11696 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11697 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11698 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11699 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11700 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11701 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11702 | |
| 11703 | HttpRequestInfo request; |
| 11704 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11705 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11706 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11707 | request.traffic_annotation = |
| 11708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11709 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11710 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11711 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11713 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11714 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11716 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11717 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11718 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11719 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11721 | |
| 11722 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11723 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11724 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11725 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11726 | } |
| 11727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11728 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11729 | class FakeUploadElementReader : public UploadElementReader { |
| 11730 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11731 | FakeUploadElementReader() = default; |
| 11732 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11733 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11734 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11735 | |
| 11736 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11737 | int Init(CompletionOnceCallback callback) override { |
| 11738 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11739 | return ERR_IO_PENDING; |
| 11740 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11741 | uint64_t GetContentLength() const override { return 0; } |
| 11742 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11743 | int Read(IOBuffer* buf, |
| 11744 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11745 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11746 | return ERR_FAILED; |
| 11747 | } |
| 11748 | |
| 11749 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11750 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11751 | }; |
| 11752 | |
| 11753 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11754 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11755 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11756 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11757 | |
| 11758 | HttpRequestInfo request; |
| 11759 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11760 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11761 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11762 | request.traffic_annotation = |
| 11763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11766 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11767 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11768 | |
| 11769 | StaticSocketDataProvider data; |
| 11770 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11771 | |
| 11772 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11773 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11774 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11775 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11776 | |
| 11777 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11778 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11779 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11780 | |
| 11781 | // Return Init()'s result after the transaction gets destroyed. |
| 11782 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11783 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11784 | } |
| 11785 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11786 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11787 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11788 | HttpRequestInfo request; |
| 11789 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11790 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11791 | request.traffic_annotation = |
| 11792 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11793 | |
| 11794 | // First transaction will request a resource and receive a Basic challenge |
| 11795 | // with realm="first_realm". |
| 11796 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11797 | MockWrite( |
| 11798 | "GET / HTTP/1.1\r\n" |
| 11799 | "Host: www.example.org\r\n" |
| 11800 | "Connection: keep-alive\r\n" |
| 11801 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11802 | }; |
| 11803 | MockRead data_reads1[] = { |
| 11804 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11805 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11806 | "\r\n"), |
| 11807 | }; |
| 11808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11809 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11810 | // for first_realm. The server will reject and provide a challenge with |
| 11811 | // second_realm. |
| 11812 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11813 | MockWrite( |
| 11814 | "GET / HTTP/1.1\r\n" |
| 11815 | "Host: www.example.org\r\n" |
| 11816 | "Connection: keep-alive\r\n" |
| 11817 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11818 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11819 | }; |
| 11820 | MockRead data_reads2[] = { |
| 11821 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11822 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11823 | "\r\n"), |
| 11824 | }; |
| 11825 | |
| 11826 | // This again fails, and goes back to first_realm. Make sure that the |
| 11827 | // entry is removed from cache. |
| 11828 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11829 | MockWrite( |
| 11830 | "GET / HTTP/1.1\r\n" |
| 11831 | "Host: www.example.org\r\n" |
| 11832 | "Connection: keep-alive\r\n" |
| 11833 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11834 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11835 | }; |
| 11836 | MockRead data_reads3[] = { |
| 11837 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11838 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11839 | "\r\n"), |
| 11840 | }; |
| 11841 | |
| 11842 | // Try one last time (with the correct password) and get the resource. |
| 11843 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11844 | MockWrite( |
| 11845 | "GET / HTTP/1.1\r\n" |
| 11846 | "Host: www.example.org\r\n" |
| 11847 | "Connection: keep-alive\r\n" |
| 11848 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11849 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11850 | }; |
| 11851 | MockRead data_reads4[] = { |
| 11852 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11853 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11854 | "Content-Length: 5\r\n" |
| 11855 | "\r\n" |
| 11856 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11857 | }; |
| 11858 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11859 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11860 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11861 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11862 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11864 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11865 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11866 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11867 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11868 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11869 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11871 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11872 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11873 | // Issue the first request with Authorize headers. There should be a |
| 11874 | // password prompt for first_realm waiting to be filled in after the |
| 11875 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11876 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11878 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11879 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11880 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11881 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11882 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11883 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11884 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11885 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11886 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11887 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11888 | |
| 11889 | // Issue the second request with an incorrect password. There should be a |
| 11890 | // password prompt for second_realm waiting to be filled in after the |
| 11891 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11892 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11893 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11894 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11896 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11897 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11898 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11899 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11900 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11901 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11902 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11903 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11904 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11905 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11906 | |
| 11907 | // Issue the third request with another incorrect password. There should be |
| 11908 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11909 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11910 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11911 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11912 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11913 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11915 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11916 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11917 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11918 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11919 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11920 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11921 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11922 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11923 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11924 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11925 | |
| 11926 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11927 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11928 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11929 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11931 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11932 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11933 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11934 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11935 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11936 | } |
| 11937 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11938 | // Regression test for https://crbug.com/754395. |
| 11939 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11940 | MockRead data_reads[] = { |
| 11941 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11942 | MockRead(kAlternativeServiceHttpHeader), |
| 11943 | MockRead("\r\n"), |
| 11944 | MockRead("hello world"), |
| 11945 | MockRead(SYNCHRONOUS, OK), |
| 11946 | }; |
| 11947 | |
| 11948 | HttpRequestInfo request; |
| 11949 | request.method = "GET"; |
| 11950 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11951 | request.traffic_annotation = |
| 11952 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11954 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11955 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11956 | |
| 11957 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11958 | ssl.ssl_info.cert = |
| 11959 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11960 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11961 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11963 | |
| 11964 | TestCompletionCallback callback; |
| 11965 | |
| 11966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11968 | |
| 11969 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11971 | |
| 11972 | url::SchemeHostPort test_server(request.url); |
| 11973 | HttpServerProperties* http_server_properties = |
| 11974 | session->http_server_properties(); |
| 11975 | EXPECT_TRUE( |
| 11976 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11977 | |
| 11978 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11979 | |
| 11980 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11981 | ASSERT_TRUE(response); |
| 11982 | ASSERT_TRUE(response->headers); |
| 11983 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11984 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11985 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11986 | |
| 11987 | std::string response_data; |
| 11988 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11989 | EXPECT_EQ("hello world", response_data); |
| 11990 | |
| 11991 | EXPECT_TRUE( |
| 11992 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11993 | } |
| 11994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11995 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11996 | MockRead data_reads[] = { |
| 11997 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11998 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11999 | MockRead("\r\n"), |
| 12000 | MockRead("hello world"), |
| 12001 | MockRead(SYNCHRONOUS, OK), |
| 12002 | }; |
| 12003 | |
| 12004 | HttpRequestInfo request; |
| 12005 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12006 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12007 | request.traffic_annotation = |
| 12008 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12009 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12010 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12012 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12013 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12014 | ssl.ssl_info.cert = |
| 12015 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12016 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12017 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12018 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12019 | TestCompletionCallback callback; |
| 12020 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12022 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12023 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12024 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12026 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12027 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12028 | HttpServerProperties* http_server_properties = |
| 12029 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12030 | EXPECT_TRUE( |
| 12031 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12032 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12033 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12035 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12036 | ASSERT_TRUE(response); |
| 12037 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12038 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12039 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12040 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12041 | |
| 12042 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12043 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12044 | EXPECT_EQ("hello world", response_data); |
| 12045 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12046 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12047 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12048 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12049 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12050 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12051 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12052 | } |
| 12053 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12054 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12055 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12056 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12057 | MockRead data_reads[] = { |
| 12058 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12059 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12060 | MockRead("\r\n"), |
| 12061 | MockRead("hello world"), |
| 12062 | MockRead(SYNCHRONOUS, OK), |
| 12063 | }; |
| 12064 | |
| 12065 | HttpRequestInfo request; |
| 12066 | request.method = "GET"; |
| 12067 | request.url = GURL("http://www.example.org/"); |
| 12068 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12069 | request.traffic_annotation = |
| 12070 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12071 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12072 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12073 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12074 | |
| 12075 | TestCompletionCallback callback; |
| 12076 | |
| 12077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12079 | |
| 12080 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12081 | HttpServerProperties* http_server_properties = |
| 12082 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12083 | EXPECT_TRUE( |
| 12084 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12085 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12086 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12088 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12090 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12091 | ASSERT_TRUE(response); |
| 12092 | ASSERT_TRUE(response->headers); |
| 12093 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12094 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12095 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12096 | |
| 12097 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12098 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12099 | EXPECT_EQ("hello world", response_data); |
| 12100 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12101 | EXPECT_TRUE( |
| 12102 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12103 | } |
| 12104 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12105 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12106 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12107 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12108 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12109 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12110 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12111 | HttpRequestInfo request; |
| 12112 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12113 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12114 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12115 | request.traffic_annotation = |
| 12116 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12117 | |
| 12118 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12119 | StaticSocketDataProvider first_data; |
| 12120 | first_data.set_connect_data(mock_connect); |
| 12121 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12122 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12123 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12125 | |
| 12126 | MockRead data_reads[] = { |
| 12127 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12128 | MockRead(ASYNC, OK), |
| 12129 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12130 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12131 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12132 | |
| 12133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12134 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12135 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12136 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12137 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12138 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12139 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12140 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12141 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12143 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12144 | TestCompletionCallback callback; |
| 12145 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12146 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12147 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12148 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12149 | } |
| 12150 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12151 | // Regression test for https://crbug.com/615497: |
| 12152 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12153 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12154 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12155 | HttpRequestInfo request; |
| 12156 | request.method = "GET"; |
| 12157 | request.url = GURL("http://www.example.org/"); |
| 12158 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12159 | request.traffic_annotation = |
| 12160 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12161 | |
| 12162 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12163 | StaticSocketDataProvider first_data; |
| 12164 | first_data.set_connect_data(mock_connect); |
| 12165 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12166 | |
| 12167 | MockRead data_reads[] = { |
| 12168 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12169 | MockRead(ASYNC, OK), |
| 12170 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12171 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12172 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12173 | |
| 12174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12175 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12176 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12177 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12178 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12179 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12180 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12181 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12183 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12184 | TestCompletionCallback callback; |
| 12185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12186 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12187 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12188 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12189 | } |
| 12190 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12191 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12192 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12194 | HttpServerProperties* http_server_properties = |
| 12195 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12196 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12197 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12198 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12199 | http_server_properties->SetQuicAlternativeService( |
| 12200 | test_server, alternative_service, expiration, |
| 12201 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12202 | EXPECT_EQ( |
| 12203 | 1u, |
| 12204 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12205 | |
| 12206 | // Send a clear header. |
| 12207 | MockRead data_reads[] = { |
| 12208 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12209 | MockRead("Alt-Svc: clear\r\n"), |
| 12210 | MockRead("\r\n"), |
| 12211 | MockRead("hello world"), |
| 12212 | MockRead(SYNCHRONOUS, OK), |
| 12213 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12214 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12216 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12217 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12218 | ssl.ssl_info.cert = |
| 12219 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12220 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12221 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12222 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12223 | HttpRequestInfo request; |
| 12224 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12225 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12226 | request.traffic_annotation = |
| 12227 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12228 | |
| 12229 | TestCompletionCallback callback; |
| 12230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12232 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12233 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12234 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12236 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12237 | ASSERT_TRUE(response); |
| 12238 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12239 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12240 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12241 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12242 | |
| 12243 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12244 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12245 | EXPECT_EQ("hello world", response_data); |
| 12246 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12247 | EXPECT_TRUE( |
| 12248 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12249 | } |
| 12250 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12251 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12252 | MockRead data_reads[] = { |
| 12253 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12254 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12255 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12256 | MockRead("hello world"), |
| 12257 | MockRead(SYNCHRONOUS, OK), |
| 12258 | }; |
| 12259 | |
| 12260 | HttpRequestInfo request; |
| 12261 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12262 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12263 | request.traffic_annotation = |
| 12264 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12266 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12267 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12268 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12269 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12270 | ssl.ssl_info.cert = |
| 12271 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12272 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12274 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12275 | TestCompletionCallback callback; |
| 12276 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12279 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12280 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12282 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12283 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12284 | HttpServerProperties* http_server_properties = |
| 12285 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12286 | EXPECT_TRUE( |
| 12287 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12288 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12289 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12290 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12291 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12292 | ASSERT_TRUE(response); |
| 12293 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12294 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12295 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12296 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12297 | |
| 12298 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12299 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12300 | EXPECT_EQ("hello world", response_data); |
| 12301 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12302 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12303 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12304 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12305 | |
| 12306 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12307 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12308 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12309 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12310 | 1234); |
| 12311 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12312 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12313 | } |
| 12314 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12315 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12316 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12317 | HostPortPair alternative("alternative.example.org", 443); |
| 12318 | std::string origin_url = "https://origin.example.org:443"; |
| 12319 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12320 | |
| 12321 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12322 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12323 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12325 | |
| 12326 | // HTTP/1.1 data for request. |
| 12327 | MockWrite http_writes[] = { |
| 12328 | MockWrite("GET / HTTP/1.1\r\n" |
| 12329 | "Host: alternative.example.org\r\n" |
| 12330 | "Connection: keep-alive\r\n\r\n"), |
| 12331 | }; |
| 12332 | |
| 12333 | MockRead http_reads[] = { |
| 12334 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12335 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12336 | "Content-Length: 40\r\n\r\n" |
| 12337 | "first HTTP/1.1 response from alternative"), |
| 12338 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12339 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12340 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12341 | |
| 12342 | StaticSocketDataProvider data_refused; |
| 12343 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12344 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12345 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12346 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12348 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12349 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12350 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12351 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12352 | http_server_properties->SetQuicAlternativeService( |
| 12353 | server, alternative_service, expiration, |
| 12354 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12355 | // Mark the QUIC alternative service as broken. |
| 12356 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12357 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12358 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12359 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12360 | request.method = "GET"; |
| 12361 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12362 | request.traffic_annotation = |
| 12363 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12364 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12365 | TestCompletionCallback callback; |
| 12366 | NetErrorDetails details; |
| 12367 | EXPECT_FALSE(details.quic_broken); |
| 12368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12369 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12370 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12371 | EXPECT_TRUE(details.quic_broken); |
| 12372 | } |
| 12373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12374 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12375 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12376 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12377 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12378 | std::string origin_url = "https://origin.example.org:443"; |
| 12379 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12380 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12381 | |
| 12382 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12383 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12384 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12386 | |
| 12387 | // HTTP/1.1 data for request. |
| 12388 | MockWrite http_writes[] = { |
| 12389 | MockWrite("GET / HTTP/1.1\r\n" |
| 12390 | "Host: alternative1.example.org\r\n" |
| 12391 | "Connection: keep-alive\r\n\r\n"), |
| 12392 | }; |
| 12393 | |
| 12394 | MockRead http_reads[] = { |
| 12395 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12396 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12397 | "Content-Length: 40\r\n\r\n" |
| 12398 | "first HTTP/1.1 response from alternative1"), |
| 12399 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12400 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12401 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12402 | |
| 12403 | StaticSocketDataProvider data_refused; |
| 12404 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12405 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12406 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12408 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12409 | session->http_server_properties(); |
| 12410 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12411 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12412 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12413 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12414 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12415 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12416 | alternative_service_info_vector.push_back( |
| 12417 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12418 | alternative_service1, expiration, |
| 12419 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12420 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12421 | alternative_service_info_vector.push_back( |
| 12422 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12423 | alternative_service2, expiration, |
| 12424 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12425 | |
| 12426 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12427 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12428 | |
| 12429 | // Mark one of the QUIC alternative service as broken. |
| 12430 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12431 | EXPECT_EQ(2u, |
| 12432 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12433 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12434 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12436 | request.method = "GET"; |
| 12437 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12438 | request.traffic_annotation = |
| 12439 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12440 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12441 | TestCompletionCallback callback; |
| 12442 | NetErrorDetails details; |
| 12443 | EXPECT_FALSE(details.quic_broken); |
| 12444 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12445 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12446 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12447 | EXPECT_FALSE(details.quic_broken); |
| 12448 | } |
| 12449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12450 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12451 | HttpRequestInfo request; |
| 12452 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12453 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12454 | request.traffic_annotation = |
| 12455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12456 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12457 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12458 | StaticSocketDataProvider first_data; |
| 12459 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12460 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12461 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12462 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12464 | |
| 12465 | MockRead data_reads[] = { |
| 12466 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12467 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12468 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12469 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12470 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12471 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12472 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12474 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12475 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12476 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12477 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12478 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12479 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12480 | // Port is ignored by MockConnect anyway. |
| 12481 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12482 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12483 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12484 | http_server_properties->SetHttp2AlternativeService( |
| 12485 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12487 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12488 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12489 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12490 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12492 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12494 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12495 | ASSERT_TRUE(response); |
| 12496 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12497 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12498 | |
| 12499 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12500 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12501 | EXPECT_EQ("hello world", response_data); |
| 12502 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12503 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12504 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12505 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12506 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12507 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12508 | EXPECT_TRUE( |
| 12509 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12510 | } |
| 12511 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12512 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12513 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12514 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12515 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12516 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12517 | HttpRequestInfo restricted_port_request; |
| 12518 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12519 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12520 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12521 | restricted_port_request.traffic_annotation = |
| 12522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12523 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12524 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12525 | StaticSocketDataProvider first_data; |
| 12526 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12527 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12528 | |
| 12529 | MockRead data_reads[] = { |
| 12530 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12531 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12532 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12533 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12534 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12535 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12536 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12537 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12541 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12542 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12543 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12544 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12545 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12546 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12547 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12548 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12549 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12550 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12552 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12553 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12555 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12556 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12558 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12559 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12560 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12561 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12562 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12563 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12564 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12565 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12566 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12567 | |
| 12568 | HttpRequestInfo restricted_port_request; |
| 12569 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12570 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12571 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12572 | restricted_port_request.traffic_annotation = |
| 12573 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12574 | |
| 12575 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12576 | StaticSocketDataProvider first_data; |
| 12577 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12578 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12579 | |
| 12580 | MockRead data_reads[] = { |
| 12581 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12582 | MockRead("hello world"), |
| 12583 | MockRead(ASYNC, OK), |
| 12584 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12585 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12586 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12587 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12588 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12589 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12590 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12592 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12593 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12594 | session->http_server_properties(); |
| 12595 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12596 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12597 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12598 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12599 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12600 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12601 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12604 | TestCompletionCallback callback; |
| 12605 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12606 | EXPECT_EQ(ERR_IO_PENDING, |
| 12607 | trans.Start(&restricted_port_request, callback.callback(), |
| 12608 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12609 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12610 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12611 | } |
| 12612 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12613 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12614 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12615 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12616 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12617 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12618 | HttpRequestInfo restricted_port_request; |
| 12619 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12620 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12621 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12622 | restricted_port_request.traffic_annotation = |
| 12623 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12624 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12625 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12626 | StaticSocketDataProvider first_data; |
| 12627 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12628 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12629 | |
| 12630 | MockRead data_reads[] = { |
| 12631 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12632 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12633 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12634 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12635 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12636 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12637 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12638 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12639 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12640 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12642 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12643 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12644 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12645 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12646 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12647 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12648 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12649 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12650 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12651 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12653 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12654 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12656 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12657 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12659 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12660 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12661 | } |
| 12662 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12663 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12664 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12665 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12666 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12667 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12668 | HttpRequestInfo unrestricted_port_request; |
| 12669 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12670 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12671 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12672 | unrestricted_port_request.traffic_annotation = |
| 12673 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12674 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12675 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12676 | StaticSocketDataProvider first_data; |
| 12677 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12678 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12679 | |
| 12680 | MockRead data_reads[] = { |
| 12681 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12682 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12683 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12684 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12685 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12686 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12687 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12688 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12692 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12693 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12694 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12695 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12696 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12697 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12698 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12699 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12700 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12701 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12704 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12706 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12707 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12709 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12710 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12711 | } |
| 12712 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12713 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12714 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12715 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12716 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12717 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12718 | HttpRequestInfo unrestricted_port_request; |
| 12719 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12720 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12721 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12722 | unrestricted_port_request.traffic_annotation = |
| 12723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12724 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12725 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12726 | StaticSocketDataProvider first_data; |
| 12727 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12728 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12729 | |
| 12730 | MockRead data_reads[] = { |
| 12731 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12732 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12733 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12734 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12735 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12736 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12737 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12738 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12739 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12740 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12741 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12742 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12743 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12744 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12745 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12746 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12747 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12748 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12749 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12750 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12751 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12754 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12756 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12757 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12759 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12760 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12761 | } |
| 12762 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12763 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12764 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12765 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12766 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12767 | HttpRequestInfo request; |
| 12768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12769 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12770 | request.traffic_annotation = |
| 12771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12772 | |
| 12773 | // The alternate protocol request will error out before we attempt to connect, |
| 12774 | // so only the standard HTTP request will try to connect. |
| 12775 | MockRead data_reads[] = { |
| 12776 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12777 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12778 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12779 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12780 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12782 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12784 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12785 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12786 | session->http_server_properties(); |
| 12787 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12788 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12789 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12790 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12791 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12792 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12795 | TestCompletionCallback callback; |
| 12796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12797 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12799 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12800 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12802 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12803 | ASSERT_TRUE(response); |
| 12804 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12805 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12806 | |
| 12807 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12808 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12809 | EXPECT_EQ("hello world", response_data); |
| 12810 | } |
| 12811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12812 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12813 | HttpRequestInfo request; |
| 12814 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12815 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12816 | request.traffic_annotation = |
| 12817 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12818 | |
| 12819 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12820 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12821 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12822 | MockRead("\r\n"), |
| 12823 | MockRead("hello world"), |
| 12824 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12825 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12826 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12827 | StaticSocketDataProvider first_transaction(data_reads, |
| 12828 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12829 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12830 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12831 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12832 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12833 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12834 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12835 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12836 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12837 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12838 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12839 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12840 | spdy::SpdySerializedFrame resp( |
| 12841 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12842 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12843 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12844 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12845 | }; |
| 12846 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12847 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12848 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12849 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12850 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12851 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12852 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12853 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12854 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12855 | &hanging_non_alternate_protocol_socket); |
| 12856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12857 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12860 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12861 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12863 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12865 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12866 | |
| 12867 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12868 | ASSERT_TRUE(response); |
| 12869 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12870 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12871 | |
| 12872 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12873 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12874 | EXPECT_EQ("hello world", response_data); |
| 12875 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12876 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12877 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12879 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12881 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12882 | |
| 12883 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12884 | ASSERT_TRUE(response); |
| 12885 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12886 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12887 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12888 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12889 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12890 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12891 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12892 | } |
| 12893 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12894 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12895 | HttpRequestInfo request; |
| 12896 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12897 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12898 | request.traffic_annotation = |
| 12899 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12900 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12901 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12902 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12903 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12904 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12905 | MockRead("\r\n"), |
| 12906 | MockRead("hello world"), |
| 12907 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12908 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12909 | }; |
| 12910 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12911 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12912 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12913 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12914 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12915 | ssl_http11.ssl_info.cert = |
| 12916 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12917 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12918 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12919 | |
| 12920 | // Second transaction starts an alternative and a non-alternative Job. |
| 12921 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12922 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12923 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12924 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12925 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12926 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12927 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12928 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12929 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12930 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12931 | // Third transaction starts an alternative and a non-alternative job. |
| 12932 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12933 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12934 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12935 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12936 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12937 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12938 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12939 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12940 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12941 | spdy::SpdySerializedFrame resp1( |
| 12942 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12943 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12944 | spdy::SpdySerializedFrame resp2( |
| 12945 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12946 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12947 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12948 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12949 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12950 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12951 | }; |
| 12952 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12953 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12954 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12955 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12956 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12957 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12958 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12959 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12960 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12961 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12962 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12963 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12964 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12965 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12966 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12967 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12968 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12969 | |
| 12970 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12971 | ASSERT_TRUE(response); |
| 12972 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12973 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12974 | |
| 12975 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12976 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12977 | EXPECT_EQ("hello world", response_data); |
| 12978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12979 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12980 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12981 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12984 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12985 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12986 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12988 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12989 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12990 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12991 | |
| 12992 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12993 | ASSERT_TRUE(response); |
| 12994 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12995 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12996 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12997 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12998 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12999 | EXPECT_EQ("hello!", response_data); |
| 13000 | |
| 13001 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13002 | ASSERT_TRUE(response); |
| 13003 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13004 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13005 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13006 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13007 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13008 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13009 | } |
| 13010 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13011 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13012 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13013 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13014 | HttpRequestInfo request; |
| 13015 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13016 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13017 | request.traffic_annotation = |
| 13018 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13019 | |
| 13020 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13021 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13022 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13023 | MockRead("\r\n"), |
| 13024 | MockRead("hello world"), |
| 13025 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13026 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13027 | }; |
| 13028 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13029 | StaticSocketDataProvider first_transaction(data_reads, |
| 13030 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13031 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13032 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13033 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13034 | ssl.ssl_info.cert = |
| 13035 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13036 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13038 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13039 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13040 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13041 | hanging_alternate_protocol_socket.set_connect_data( |
| 13042 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13043 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13044 | &hanging_alternate_protocol_socket); |
| 13045 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13046 | // 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] | 13047 | StaticSocketDataProvider second_transaction(data_reads, |
| 13048 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13049 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13052 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13055 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13056 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13057 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13058 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13060 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13061 | |
| 13062 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13063 | ASSERT_TRUE(response); |
| 13064 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13065 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13066 | |
| 13067 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13068 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13069 | EXPECT_EQ("hello world", response_data); |
| 13070 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13071 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13072 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13073 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13074 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13075 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13076 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13077 | |
| 13078 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13079 | ASSERT_TRUE(response); |
| 13080 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13081 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13082 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13083 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13084 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13085 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13086 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13087 | } |
| 13088 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13089 | // Test that proxy is resolved using the origin url, |
| 13090 | // regardless of the alternative server. |
| 13091 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13092 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13093 | ProxyConfig proxy_config; |
| 13094 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13095 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13096 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13097 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13098 | |
| 13099 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13100 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13101 | &capturing_proxy_resolver); |
| 13102 | |
| 13103 | TestNetLog net_log; |
| 13104 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13105 | session_deps_.proxy_resolution_service = |
| 13106 | std::make_unique<ProxyResolutionService>( |
| 13107 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13108 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13109 | |
| 13110 | session_deps_.net_log = &net_log; |
| 13111 | |
| 13112 | // Configure alternative service with a hostname that is not bypassed by the |
| 13113 | // proxy. |
| 13114 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13115 | HttpServerProperties* http_server_properties = |
| 13116 | session->http_server_properties(); |
| 13117 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13118 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13119 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13120 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13121 | http_server_properties->SetHttp2AlternativeService( |
| 13122 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13123 | |
| 13124 | // Non-alternative job should hang. |
| 13125 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13126 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13127 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13128 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13129 | &hanging_alternate_protocol_socket); |
| 13130 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13131 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13132 | |
| 13133 | HttpRequestInfo request; |
| 13134 | request.method = "GET"; |
| 13135 | request.url = GURL("https://www.example.org/"); |
| 13136 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13137 | request.traffic_annotation = |
| 13138 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13139 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13140 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13141 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13142 | |
| 13143 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13144 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13145 | spdy::SpdySerializedFrame resp( |
| 13146 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13147 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13148 | MockRead spdy_reads[] = { |
| 13149 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13150 | }; |
| 13151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13152 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13153 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13154 | |
| 13155 | TestCompletionCallback callback; |
| 13156 | |
| 13157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13158 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13159 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13160 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13161 | |
| 13162 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13163 | ASSERT_TRUE(response); |
| 13164 | ASSERT_TRUE(response->headers); |
| 13165 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13166 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13167 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13168 | |
| 13169 | std::string response_data; |
| 13170 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13171 | EXPECT_EQ("hello!", response_data); |
| 13172 | |
| 13173 | // Origin host bypasses proxy, no resolution should have happened. |
| 13174 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13175 | } |
| 13176 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13177 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13178 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13179 | proxy_config.set_auto_detect(true); |
| 13180 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13181 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13182 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13183 | session_deps_.proxy_resolution_service = |
| 13184 | std::make_unique<ProxyResolutionService>( |
| 13185 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13186 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13187 | std::make_unique<CapturingProxyResolverFactory>( |
| 13188 | &capturing_proxy_resolver), |
| 13189 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13190 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13191 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13192 | |
| 13193 | HttpRequestInfo request; |
| 13194 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13195 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13196 | request.traffic_annotation = |
| 13197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13198 | |
| 13199 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13200 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13201 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13202 | MockRead("\r\n"), |
| 13203 | MockRead("hello world"), |
| 13204 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13205 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13206 | }; |
| 13207 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13208 | StaticSocketDataProvider first_transaction(data_reads, |
| 13209 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13210 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13211 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13212 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13214 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13215 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13216 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13217 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13218 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13219 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13220 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13221 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13222 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13223 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13224 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13225 | }; |
| 13226 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13227 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13228 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13229 | spdy::SpdySerializedFrame resp( |
| 13230 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13231 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13232 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13233 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13234 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13235 | }; |
| 13236 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13237 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13238 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13239 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13240 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13241 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13242 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13243 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13244 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13245 | &hanging_non_alternate_protocol_socket); |
| 13246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13247 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13250 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13251 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13253 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13255 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13256 | |
| 13257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13258 | ASSERT_TRUE(response); |
| 13259 | ASSERT_TRUE(response->headers); |
| 13260 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13261 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13262 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13263 | |
| 13264 | std::string response_data; |
| 13265 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13266 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13267 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13268 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13269 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13270 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13271 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13272 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13273 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13274 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13275 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13276 | ASSERT_TRUE(response); |
| 13277 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13278 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13279 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13280 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13281 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13282 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13283 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13284 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13285 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13286 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13287 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13288 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13289 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13290 | LoadTimingInfo load_timing_info; |
| 13291 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13292 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13293 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13294 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13295 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13296 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13297 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13298 | HttpRequestInfo request; |
| 13299 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13300 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13301 | request.traffic_annotation = |
| 13302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13303 | |
| 13304 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13305 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13306 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13307 | MockRead("\r\n"), |
| 13308 | MockRead("hello world"), |
| 13309 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13310 | }; |
| 13311 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13312 | StaticSocketDataProvider first_transaction(data_reads, |
| 13313 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13314 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13315 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13316 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13318 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13319 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13320 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13321 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13322 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13323 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13324 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13325 | spdy::SpdySerializedFrame resp( |
| 13326 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13327 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13328 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13329 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13330 | }; |
| 13331 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13332 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13333 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13334 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13335 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13338 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13339 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13340 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13341 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13342 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13343 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13344 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13345 | |
| 13346 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13347 | ASSERT_TRUE(response); |
| 13348 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13349 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13350 | |
| 13351 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13352 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13353 | EXPECT_EQ("hello world", response_data); |
| 13354 | |
| 13355 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13356 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13357 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13358 | PRIVACY_MODE_DISABLED, |
| 13359 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13360 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13361 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13362 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13363 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13364 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13366 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13368 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13369 | |
| 13370 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13371 | ASSERT_TRUE(response); |
| 13372 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13373 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13374 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13375 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13376 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13377 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13378 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13379 | } |
| 13380 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13381 | // GenerateAuthToken is a mighty big test. |
| 13382 | // It tests all permutation of GenerateAuthToken behavior: |
| 13383 | // - Synchronous and Asynchronous completion. |
| 13384 | // - OK or error on completion. |
| 13385 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13386 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13387 | // - Non-authenticating and authenticating backend. |
| 13388 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13389 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13390 | // problems generating an auth token for an authenticating proxy, we don't |
| 13391 | // need to test all permutations of the backend server). |
| 13392 | // |
| 13393 | // The test proceeds by going over each of the configuration cases, and |
| 13394 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13395 | // specifies both the configuration for the test as well as the expectations |
| 13396 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13397 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13398 | static const char kServer[] = "http://www.example.com"; |
| 13399 | static const char kSecureServer[] = "https://www.example.com"; |
| 13400 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13401 | |
| 13402 | enum AuthTiming { |
| 13403 | AUTH_NONE, |
| 13404 | AUTH_SYNC, |
| 13405 | AUTH_ASYNC, |
| 13406 | }; |
| 13407 | |
| 13408 | const MockWrite kGet( |
| 13409 | "GET / HTTP/1.1\r\n" |
| 13410 | "Host: www.example.com\r\n" |
| 13411 | "Connection: keep-alive\r\n\r\n"); |
| 13412 | const MockWrite kGetProxy( |
| 13413 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13414 | "Host: www.example.com\r\n" |
| 13415 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13416 | const MockWrite kGetAuth( |
| 13417 | "GET / HTTP/1.1\r\n" |
| 13418 | "Host: www.example.com\r\n" |
| 13419 | "Connection: keep-alive\r\n" |
| 13420 | "Authorization: auth_token\r\n\r\n"); |
| 13421 | const MockWrite kGetProxyAuth( |
| 13422 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13423 | "Host: www.example.com\r\n" |
| 13424 | "Proxy-Connection: keep-alive\r\n" |
| 13425 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13426 | const MockWrite kGetAuthThroughProxy( |
| 13427 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13428 | "Host: www.example.com\r\n" |
| 13429 | "Proxy-Connection: keep-alive\r\n" |
| 13430 | "Authorization: auth_token\r\n\r\n"); |
| 13431 | const MockWrite kGetAuthWithProxyAuth( |
| 13432 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13433 | "Host: www.example.com\r\n" |
| 13434 | "Proxy-Connection: keep-alive\r\n" |
| 13435 | "Proxy-Authorization: auth_token\r\n" |
| 13436 | "Authorization: auth_token\r\n\r\n"); |
| 13437 | const MockWrite kConnect( |
| 13438 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13439 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13440 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13441 | const MockWrite kConnectProxyAuth( |
| 13442 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13443 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13444 | "Proxy-Connection: keep-alive\r\n" |
| 13445 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13446 | |
| 13447 | const MockRead kSuccess( |
| 13448 | "HTTP/1.1 200 OK\r\n" |
| 13449 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13450 | "Content-Length: 3\r\n\r\n" |
| 13451 | "Yes"); |
| 13452 | const MockRead kFailure( |
| 13453 | "Should not be called."); |
| 13454 | const MockRead kServerChallenge( |
| 13455 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13456 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13457 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13458 | "Content-Length: 14\r\n\r\n" |
| 13459 | "Unauthorized\r\n"); |
| 13460 | const MockRead kProxyChallenge( |
| 13461 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13462 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13463 | "Proxy-Connection: close\r\n" |
| 13464 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13465 | "Content-Length: 14\r\n\r\n" |
| 13466 | "Unauthorized\r\n"); |
| 13467 | const MockRead kProxyConnected( |
| 13468 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13469 | |
| 13470 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13471 | // no constructors, but the C++ compiler on Windows warns about |
| 13472 | // unspecified data in compound literals. So, moved to using constructors, |
| 13473 | // and TestRound's created with the default constructor should not be used. |
| 13474 | struct TestRound { |
| 13475 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13476 | : expected_rv(ERR_UNEXPECTED), |
| 13477 | extra_write(nullptr), |
| 13478 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13479 | TestRound(const MockWrite& write_arg, |
| 13480 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13481 | int expected_rv_arg) |
| 13482 | : write(write_arg), |
| 13483 | read(read_arg), |
| 13484 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13485 | extra_write(nullptr), |
| 13486 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13487 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13488 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13489 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13490 | : write(write_arg), |
| 13491 | read(read_arg), |
| 13492 | expected_rv(expected_rv_arg), |
| 13493 | extra_write(extra_write_arg), |
| 13494 | extra_read(extra_read_arg) { |
| 13495 | } |
| 13496 | MockWrite write; |
| 13497 | MockRead read; |
| 13498 | int expected_rv; |
| 13499 | const MockWrite* extra_write; |
| 13500 | const MockRead* extra_read; |
| 13501 | }; |
| 13502 | |
| 13503 | static const int kNoSSL = 500; |
| 13504 | |
| 13505 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13506 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13507 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13508 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13509 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13510 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13511 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13512 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13513 | int num_auth_rounds; |
| 13514 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13515 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13516 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13517 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13518 | {__LINE__, |
| 13519 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13520 | AUTH_NONE, |
| 13521 | OK, |
| 13522 | kServer, |
| 13523 | AUTH_NONE, |
| 13524 | OK, |
| 13525 | 1, |
| 13526 | kNoSSL, |
| 13527 | {TestRound(kGet, kSuccess, OK)}}, |
| 13528 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13529 | {__LINE__, |
| 13530 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13531 | AUTH_NONE, |
| 13532 | OK, |
| 13533 | kServer, |
| 13534 | AUTH_SYNC, |
| 13535 | OK, |
| 13536 | 2, |
| 13537 | kNoSSL, |
| 13538 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13539 | TestRound(kGetAuth, kSuccess, OK)}}, |
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_SYNC, |
| 13546 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13547 | 3, |
| 13548 | kNoSSL, |
| 13549 | {TestRound(kGet, kServerChallenge, OK), |
| 13550 | TestRound(kGet, kServerChallenge, OK), |
| 13551 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13552 | {__LINE__, |
| 13553 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13554 | AUTH_NONE, |
| 13555 | OK, |
| 13556 | kServer, |
| 13557 | AUTH_SYNC, |
| 13558 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13559 | 2, |
| 13560 | kNoSSL, |
| 13561 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13562 | {__LINE__, |
| 13563 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13564 | AUTH_NONE, |
| 13565 | OK, |
| 13566 | kServer, |
| 13567 | AUTH_SYNC, |
| 13568 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13569 | 2, |
| 13570 | kNoSSL, |
| 13571 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13572 | {__LINE__, |
| 13573 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13574 | AUTH_SYNC, |
| 13575 | ERR_FAILED, |
| 13576 | kServer, |
| 13577 | AUTH_NONE, |
| 13578 | OK, |
| 13579 | 2, |
| 13580 | kNoSSL, |
| 13581 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13582 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13583 | {__LINE__, |
| 13584 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13585 | AUTH_ASYNC, |
| 13586 | ERR_FAILED, |
| 13587 | kServer, |
| 13588 | AUTH_NONE, |
| 13589 | OK, |
| 13590 | 2, |
| 13591 | kNoSSL, |
| 13592 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13593 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13594 | {__LINE__, |
| 13595 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13596 | AUTH_NONE, |
| 13597 | OK, |
| 13598 | kServer, |
| 13599 | AUTH_SYNC, |
| 13600 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13601 | 2, |
| 13602 | kNoSSL, |
| 13603 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13604 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13605 | {__LINE__, |
| 13606 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13607 | AUTH_NONE, |
| 13608 | OK, |
| 13609 | kServer, |
| 13610 | AUTH_ASYNC, |
| 13611 | ERR_FAILED, |
| 13612 | 2, |
| 13613 | kNoSSL, |
| 13614 | {TestRound(kGet, kServerChallenge, OK), |
| 13615 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13616 | {__LINE__, |
| 13617 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13618 | AUTH_NONE, |
| 13619 | OK, |
| 13620 | kServer, |
| 13621 | AUTH_ASYNC, |
| 13622 | OK, |
| 13623 | 2, |
| 13624 | kNoSSL, |
| 13625 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13626 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13627 | {__LINE__, |
| 13628 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13629 | AUTH_NONE, |
| 13630 | OK, |
| 13631 | kServer, |
| 13632 | AUTH_ASYNC, |
| 13633 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13634 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13635 | kNoSSL, |
| 13636 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13637 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13638 | TestRound(kGet, kServerChallenge, OK), |
| 13639 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13640 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13641 | {__LINE__, |
| 13642 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13643 | AUTH_NONE, |
| 13644 | OK, |
| 13645 | kServer, |
| 13646 | AUTH_NONE, |
| 13647 | OK, |
| 13648 | 1, |
| 13649 | kNoSSL, |
| 13650 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13651 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13652 | {__LINE__, |
| 13653 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13654 | AUTH_NONE, |
| 13655 | OK, |
| 13656 | kServer, |
| 13657 | AUTH_SYNC, |
| 13658 | OK, |
| 13659 | 2, |
| 13660 | kNoSSL, |
| 13661 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13662 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13663 | {__LINE__, |
| 13664 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13665 | AUTH_NONE, |
| 13666 | OK, |
| 13667 | kServer, |
| 13668 | AUTH_SYNC, |
| 13669 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13670 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13671 | kNoSSL, |
| 13672 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13673 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13674 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13675 | {__LINE__, |
| 13676 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13677 | AUTH_NONE, |
| 13678 | OK, |
| 13679 | kServer, |
| 13680 | AUTH_ASYNC, |
| 13681 | OK, |
| 13682 | 2, |
| 13683 | kNoSSL, |
| 13684 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13685 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13686 | {__LINE__, |
| 13687 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13688 | AUTH_NONE, |
| 13689 | OK, |
| 13690 | kServer, |
| 13691 | AUTH_ASYNC, |
| 13692 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13693 | 2, |
| 13694 | kNoSSL, |
| 13695 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13696 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13697 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13698 | {__LINE__, |
| 13699 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13700 | AUTH_SYNC, |
| 13701 | OK, |
| 13702 | kServer, |
| 13703 | AUTH_NONE, |
| 13704 | OK, |
| 13705 | 2, |
| 13706 | kNoSSL, |
| 13707 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13708 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13709 | {__LINE__, |
| 13710 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13711 | AUTH_SYNC, |
| 13712 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13713 | kServer, |
| 13714 | AUTH_NONE, |
| 13715 | OK, |
| 13716 | 2, |
| 13717 | kNoSSL, |
| 13718 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13719 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13720 | {__LINE__, |
| 13721 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13722 | AUTH_ASYNC, |
| 13723 | OK, |
| 13724 | kServer, |
| 13725 | AUTH_NONE, |
| 13726 | OK, |
| 13727 | 2, |
| 13728 | kNoSSL, |
| 13729 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13730 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13731 | {__LINE__, |
| 13732 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13733 | AUTH_ASYNC, |
| 13734 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13735 | kServer, |
| 13736 | AUTH_NONE, |
| 13737 | OK, |
| 13738 | 2, |
| 13739 | kNoSSL, |
| 13740 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13741 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13742 | {__LINE__, |
| 13743 | kProxy, |
| 13744 | AUTH_ASYNC, |
| 13745 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13746 | kServer, |
| 13747 | AUTH_NONE, |
| 13748 | OK, |
| 13749 | 3, |
| 13750 | kNoSSL, |
| 13751 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13752 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13753 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13754 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13755 | {__LINE__, |
| 13756 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13757 | AUTH_SYNC, |
| 13758 | OK, |
| 13759 | kServer, |
| 13760 | AUTH_SYNC, |
| 13761 | OK, |
| 13762 | 3, |
| 13763 | kNoSSL, |
| 13764 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13765 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13766 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13767 | {__LINE__, |
| 13768 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13769 | AUTH_SYNC, |
| 13770 | OK, |
| 13771 | kServer, |
| 13772 | AUTH_SYNC, |
| 13773 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13774 | 3, |
| 13775 | kNoSSL, |
| 13776 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13777 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13778 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13779 | {__LINE__, |
| 13780 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13781 | AUTH_ASYNC, |
| 13782 | OK, |
| 13783 | kServer, |
| 13784 | AUTH_SYNC, |
| 13785 | OK, |
| 13786 | 3, |
| 13787 | kNoSSL, |
| 13788 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13789 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13790 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13791 | {__LINE__, |
| 13792 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13793 | AUTH_ASYNC, |
| 13794 | OK, |
| 13795 | kServer, |
| 13796 | AUTH_SYNC, |
| 13797 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13798 | 3, |
| 13799 | kNoSSL, |
| 13800 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13801 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13802 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13803 | {__LINE__, |
| 13804 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13805 | AUTH_SYNC, |
| 13806 | OK, |
| 13807 | kServer, |
| 13808 | AUTH_ASYNC, |
| 13809 | OK, |
| 13810 | 3, |
| 13811 | kNoSSL, |
| 13812 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13813 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13814 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13815 | {__LINE__, |
| 13816 | kProxy, |
| 13817 | AUTH_SYNC, |
| 13818 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13819 | kServer, |
| 13820 | AUTH_ASYNC, |
| 13821 | OK, |
| 13822 | 4, |
| 13823 | kNoSSL, |
| 13824 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13825 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13826 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13827 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13828 | {__LINE__, |
| 13829 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13830 | AUTH_SYNC, |
| 13831 | OK, |
| 13832 | kServer, |
| 13833 | AUTH_ASYNC, |
| 13834 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13835 | 3, |
| 13836 | kNoSSL, |
| 13837 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13838 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13839 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13840 | {__LINE__, |
| 13841 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13842 | AUTH_ASYNC, |
| 13843 | OK, |
| 13844 | kServer, |
| 13845 | AUTH_ASYNC, |
| 13846 | OK, |
| 13847 | 3, |
| 13848 | kNoSSL, |
| 13849 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13850 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13851 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13852 | {__LINE__, |
| 13853 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13854 | AUTH_ASYNC, |
| 13855 | OK, |
| 13856 | kServer, |
| 13857 | AUTH_ASYNC, |
| 13858 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13859 | 3, |
| 13860 | kNoSSL, |
| 13861 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13862 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13863 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13864 | {__LINE__, |
| 13865 | kProxy, |
| 13866 | AUTH_ASYNC, |
| 13867 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13868 | kServer, |
| 13869 | AUTH_ASYNC, |
| 13870 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13871 | 4, |
| 13872 | kNoSSL, |
| 13873 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13874 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13875 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13876 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13877 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13878 | {__LINE__, |
| 13879 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13880 | AUTH_NONE, |
| 13881 | OK, |
| 13882 | kSecureServer, |
| 13883 | AUTH_NONE, |
| 13884 | OK, |
| 13885 | 1, |
| 13886 | 0, |
| 13887 | {TestRound(kGet, kSuccess, OK)}}, |
| 13888 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13889 | {__LINE__, |
| 13890 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13891 | AUTH_NONE, |
| 13892 | OK, |
| 13893 | kSecureServer, |
| 13894 | AUTH_SYNC, |
| 13895 | OK, |
| 13896 | 2, |
| 13897 | 0, |
| 13898 | {TestRound(kGet, kServerChallenge, OK), |
[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 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13902 | AUTH_NONE, |
| 13903 | OK, |
| 13904 | kSecureServer, |
| 13905 | AUTH_SYNC, |
| 13906 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13907 | 2, |
| 13908 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13909 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13910 | {__LINE__, |
| 13911 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13912 | AUTH_NONE, |
| 13913 | OK, |
| 13914 | kSecureServer, |
| 13915 | AUTH_ASYNC, |
| 13916 | OK, |
| 13917 | 2, |
| 13918 | 0, |
| 13919 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13920 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13921 | {__LINE__, |
| 13922 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13923 | AUTH_NONE, |
| 13924 | OK, |
| 13925 | kSecureServer, |
| 13926 | AUTH_ASYNC, |
| 13927 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13928 | 2, |
| 13929 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13930 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13931 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13932 | {__LINE__, |
| 13933 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13934 | AUTH_NONE, |
| 13935 | OK, |
| 13936 | kSecureServer, |
| 13937 | AUTH_NONE, |
| 13938 | OK, |
| 13939 | 1, |
| 13940 | 0, |
| 13941 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13942 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13943 | {__LINE__, |
| 13944 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13945 | AUTH_NONE, |
| 13946 | OK, |
| 13947 | kSecureServer, |
| 13948 | AUTH_SYNC, |
| 13949 | OK, |
| 13950 | 2, |
| 13951 | 0, |
| 13952 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13953 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13954 | {__LINE__, |
| 13955 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13956 | AUTH_NONE, |
| 13957 | OK, |
| 13958 | kSecureServer, |
| 13959 | AUTH_SYNC, |
| 13960 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13961 | 2, |
| 13962 | 0, |
| 13963 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13964 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13965 | {__LINE__, |
| 13966 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13967 | AUTH_NONE, |
| 13968 | OK, |
| 13969 | kSecureServer, |
| 13970 | AUTH_ASYNC, |
| 13971 | OK, |
| 13972 | 2, |
| 13973 | 0, |
| 13974 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13975 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13976 | {__LINE__, |
| 13977 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13978 | AUTH_NONE, |
| 13979 | OK, |
| 13980 | kSecureServer, |
| 13981 | AUTH_ASYNC, |
| 13982 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13983 | 2, |
| 13984 | 0, |
| 13985 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13986 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13987 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13988 | {__LINE__, |
| 13989 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13990 | AUTH_SYNC, |
| 13991 | OK, |
| 13992 | kSecureServer, |
| 13993 | AUTH_NONE, |
| 13994 | OK, |
| 13995 | 2, |
| 13996 | 1, |
| 13997 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13998 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13999 | {__LINE__, |
| 14000 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14001 | AUTH_SYNC, |
| 14002 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14003 | kSecureServer, |
| 14004 | AUTH_NONE, |
| 14005 | OK, |
| 14006 | 2, |
| 14007 | kNoSSL, |
| 14008 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14009 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14010 | {__LINE__, |
| 14011 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14012 | AUTH_SYNC, |
| 14013 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14014 | kSecureServer, |
| 14015 | AUTH_NONE, |
| 14016 | OK, |
| 14017 | 2, |
| 14018 | kNoSSL, |
| 14019 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14020 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14021 | {__LINE__, |
| 14022 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14023 | AUTH_SYNC, |
| 14024 | ERR_UNEXPECTED, |
| 14025 | kSecureServer, |
| 14026 | AUTH_NONE, |
| 14027 | OK, |
| 14028 | 2, |
| 14029 | kNoSSL, |
| 14030 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14031 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14032 | {__LINE__, |
| 14033 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14034 | AUTH_ASYNC, |
| 14035 | OK, |
| 14036 | kSecureServer, |
| 14037 | AUTH_NONE, |
| 14038 | OK, |
| 14039 | 2, |
| 14040 | 1, |
| 14041 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14042 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14043 | {__LINE__, |
| 14044 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14045 | AUTH_ASYNC, |
| 14046 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14047 | kSecureServer, |
| 14048 | AUTH_NONE, |
| 14049 | OK, |
| 14050 | 2, |
| 14051 | kNoSSL, |
| 14052 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14053 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14054 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14055 | {__LINE__, |
| 14056 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14057 | AUTH_SYNC, |
| 14058 | OK, |
| 14059 | kSecureServer, |
| 14060 | AUTH_SYNC, |
| 14061 | OK, |
| 14062 | 3, |
| 14063 | 1, |
| 14064 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14065 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14066 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14067 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14068 | {__LINE__, |
| 14069 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14070 | AUTH_SYNC, |
| 14071 | OK, |
| 14072 | kSecureServer, |
| 14073 | AUTH_SYNC, |
| 14074 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14075 | 3, |
| 14076 | 1, |
| 14077 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14078 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14079 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14080 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14081 | {__LINE__, |
| 14082 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14083 | AUTH_ASYNC, |
| 14084 | OK, |
| 14085 | kSecureServer, |
| 14086 | AUTH_SYNC, |
| 14087 | OK, |
| 14088 | 3, |
| 14089 | 1, |
| 14090 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14091 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14092 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14093 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14094 | {__LINE__, |
| 14095 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14096 | AUTH_ASYNC, |
| 14097 | OK, |
| 14098 | kSecureServer, |
| 14099 | AUTH_SYNC, |
| 14100 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14101 | 3, |
| 14102 | 1, |
| 14103 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14104 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14105 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14106 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14107 | {__LINE__, |
| 14108 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14109 | AUTH_SYNC, |
| 14110 | OK, |
| 14111 | kSecureServer, |
| 14112 | AUTH_ASYNC, |
| 14113 | OK, |
| 14114 | 3, |
| 14115 | 1, |
| 14116 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14117 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14118 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14119 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14120 | {__LINE__, |
| 14121 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14122 | AUTH_SYNC, |
| 14123 | OK, |
| 14124 | kSecureServer, |
| 14125 | AUTH_ASYNC, |
| 14126 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14127 | 3, |
| 14128 | 1, |
| 14129 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14130 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14131 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14132 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14133 | {__LINE__, |
| 14134 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14135 | AUTH_ASYNC, |
| 14136 | OK, |
| 14137 | kSecureServer, |
| 14138 | AUTH_ASYNC, |
| 14139 | OK, |
| 14140 | 3, |
| 14141 | 1, |
| 14142 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14143 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14144 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14145 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14146 | {__LINE__, |
| 14147 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14148 | AUTH_ASYNC, |
| 14149 | OK, |
| 14150 | kSecureServer, |
| 14151 | AUTH_ASYNC, |
| 14152 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14153 | 3, |
| 14154 | 1, |
| 14155 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14156 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14157 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14158 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14159 | {__LINE__, |
| 14160 | kProxy, |
| 14161 | AUTH_ASYNC, |
| 14162 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14163 | kSecureServer, |
| 14164 | AUTH_ASYNC, |
| 14165 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14166 | 4, |
| 14167 | 2, |
| 14168 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14169 | TestRound(kConnect, kProxyChallenge, OK), |
| 14170 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14171 | &kServerChallenge), |
| 14172 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14173 | }; |
| 14174 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14175 | for (const auto& test_config : test_configs) { |
| 14176 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14177 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14178 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14179 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14180 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14181 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14182 | |
| 14183 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14184 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14185 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14186 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14187 | std::string auth_challenge = "Mock realm=proxy"; |
| 14188 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14189 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14190 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14191 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14192 | empty_ssl_info, origin, |
| 14193 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14194 | auth_handler->SetGenerateExpectation( |
| 14195 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14196 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14197 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14198 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14199 | } |
| 14200 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14201 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14202 | std::string auth_challenge = "Mock realm=server"; |
| 14203 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14204 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14205 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14206 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14207 | empty_ssl_info, origin, |
| 14208 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14209 | auth_handler->SetGenerateExpectation( |
| 14210 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14211 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14212 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14213 | |
| 14214 | // The second handler always succeeds. It should only be used where there |
| 14215 | // are multiple auth sessions for server auth in the same network |
| 14216 | // transaction using the same auth scheme. |
| 14217 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14218 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14219 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14220 | empty_ssl_info, origin, |
| 14221 | NetLogWithSource()); |
| 14222 | second_handler->SetGenerateExpectation(true, OK); |
| 14223 | auth_factory->AddMockHandler(second_handler.release(), |
| 14224 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14225 | } |
| 14226 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14227 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14228 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14229 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14230 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14231 | session_deps_.proxy_resolution_service = |
| 14232 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14233 | } |
| 14234 | |
| 14235 | HttpRequestInfo request; |
| 14236 | request.method = "GET"; |
| 14237 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14238 | request.traffic_annotation = |
| 14239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14240 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14242 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14243 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14244 | |
| 14245 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14246 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14247 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14248 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14249 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14250 | |
| 14251 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14252 | mock_reads.back().push_back(read_write_round.read); |
| 14253 | mock_writes.back().push_back(read_write_round.write); |
| 14254 | |
| 14255 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14256 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14257 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14258 | mock_reads.push_back(std::vector<MockRead>()); |
| 14259 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14260 | } |
| 14261 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14262 | if (read_write_round.extra_read) { |
| 14263 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14264 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14265 | if (read_write_round.extra_write) { |
| 14266 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14267 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14268 | |
| 14269 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14270 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14271 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14272 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14273 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14274 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14275 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14276 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14277 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14278 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14279 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14280 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14281 | } |
| 14282 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14283 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14284 | // they are as well. |
| 14285 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14286 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14287 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14288 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14289 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14290 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14291 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14292 | int rv; |
| 14293 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14294 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14295 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14296 | rv = trans.RestartWithAuth( |
| 14297 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14298 | } |
| 14299 | if (rv == ERR_IO_PENDING) |
| 14300 | rv = callback.WaitForResult(); |
| 14301 | |
| 14302 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14303 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14305 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14306 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14307 | continue; |
| 14308 | } |
| 14309 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14310 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14311 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14312 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14313 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14314 | } |
| 14315 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14316 | } |
| 14317 | } |
| 14318 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14319 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14320 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14321 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14322 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14323 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14324 | session_deps_.proxy_resolution_service = |
| 14325 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14326 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14327 | |
| 14328 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14329 | auth_handler->set_connection_based(true); |
| 14330 | std::string auth_challenge = "Mock realm=server"; |
| 14331 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14332 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14333 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14334 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14335 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14336 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14337 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14338 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14339 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14340 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14341 | HttpRequestInfo request; |
| 14342 | request.method = "GET"; |
| 14343 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14344 | request.traffic_annotation = |
| 14345 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14346 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14348 | |
| 14349 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14350 | // to validate that the TCP socket is not released to the pool between |
| 14351 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14352 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14353 | CommonConnectJobParams common_connect_job_params( |
| 14354 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14355 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14356 | 50, // Max sockets for pool |
| 14357 | 1, // Max sockets per group |
| 14358 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 14359 | ProxyServer::Direct(), false, // is_for_websockets |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14360 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14361 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14362 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14363 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14364 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14366 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14367 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14368 | |
| 14369 | const MockWrite kGet( |
| 14370 | "GET / HTTP/1.1\r\n" |
| 14371 | "Host: www.example.com\r\n" |
| 14372 | "Connection: keep-alive\r\n\r\n"); |
| 14373 | const MockWrite kGetAuth( |
| 14374 | "GET / HTTP/1.1\r\n" |
| 14375 | "Host: www.example.com\r\n" |
| 14376 | "Connection: keep-alive\r\n" |
| 14377 | "Authorization: auth_token\r\n\r\n"); |
| 14378 | |
| 14379 | const MockRead kServerChallenge( |
| 14380 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14381 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14382 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14383 | "Content-Length: 14\r\n\r\n" |
| 14384 | "Unauthorized\r\n"); |
| 14385 | const MockRead kSuccess( |
| 14386 | "HTTP/1.1 200 OK\r\n" |
| 14387 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14388 | "Content-Length: 3\r\n\r\n" |
| 14389 | "Yes"); |
| 14390 | |
| 14391 | MockWrite writes[] = { |
| 14392 | // First round |
| 14393 | kGet, |
| 14394 | // Second round |
| 14395 | kGetAuth, |
| 14396 | // Third round |
| 14397 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14398 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14399 | kGetAuth, |
| 14400 | // Competing request |
| 14401 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14402 | }; |
| 14403 | MockRead reads[] = { |
| 14404 | // First round |
| 14405 | kServerChallenge, |
| 14406 | // Second round |
| 14407 | kServerChallenge, |
| 14408 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14409 | kServerChallenge, |
| 14410 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14411 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14412 | // Competing response |
| 14413 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14414 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14415 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14416 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14417 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14418 | const ClientSocketPool::GroupId kSocketGroup( |
| 14419 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 14420 | PrivacyMode::PRIVACY_MODE_DISABLED); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14421 | |
| 14422 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14423 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14424 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14425 | if (rv == ERR_IO_PENDING) |
| 14426 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14427 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14428 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14429 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14430 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14431 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14432 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14433 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14434 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14435 | // In between rounds, another request comes in for the same domain. |
| 14436 | // It should not be able to grab the TCP socket that trans has already |
| 14437 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14438 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14439 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14440 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14441 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14443 | // callback_compete.WaitForResult at this point would stall forever, |
| 14444 | // since the HttpNetworkTransaction does not release the request back to |
| 14445 | // the pool until after authentication completes. |
| 14446 | |
| 14447 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14448 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14449 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14450 | if (rv == ERR_IO_PENDING) |
| 14451 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14452 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14453 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14454 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14455 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14456 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14457 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14458 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14459 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14460 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14461 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14462 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14463 | if (rv == ERR_IO_PENDING) |
| 14464 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14465 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14466 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14467 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14468 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14469 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14470 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14471 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14472 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14473 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14474 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14475 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14476 | if (rv == ERR_IO_PENDING) |
| 14477 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14478 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14479 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14480 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14481 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14482 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14483 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14484 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14485 | // auth handler should transition to a DONE state in concert with the remote |
| 14486 | // server. But that's not something we can test here with a mock handler. |
| 14487 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14488 | auth_handler->state()); |
| 14489 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14490 | // Read the body since the fourth round was successful. This will also |
| 14491 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14492 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14493 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14494 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14495 | if (rv == ERR_IO_PENDING) |
| 14496 | rv = callback.WaitForResult(); |
| 14497 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14498 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14499 | EXPECT_EQ(0, rv); |
| 14500 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14501 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14502 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14503 | |
| 14504 | // The competing request can now finish. Wait for the headers and then |
| 14505 | // read the body. |
| 14506 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14507 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14508 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14509 | if (rv == ERR_IO_PENDING) |
| 14510 | rv = callback.WaitForResult(); |
| 14511 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14512 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14513 | EXPECT_EQ(0, rv); |
| 14514 | |
| 14515 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14516 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14517 | } |
| 14518 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14519 | // This tests the case that a request is issued via http instead of spdy after |
| 14520 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14521 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14522 | HttpRequestInfo request; |
| 14523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14524 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14525 | request.traffic_annotation = |
| 14526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14527 | |
| 14528 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | MockWrite( |
| 14530 | "GET / HTTP/1.1\r\n" |
| 14531 | "Host: www.example.org\r\n" |
| 14532 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14533 | }; |
| 14534 | |
| 14535 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14536 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14537 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14538 | MockRead("\r\n"), |
| 14539 | MockRead("hello world"), |
| 14540 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14541 | }; |
| 14542 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14543 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14544 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14545 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14546 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14548 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14549 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14551 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14556 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14557 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14559 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14561 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14562 | ASSERT_TRUE(response); |
| 14563 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14564 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14565 | |
| 14566 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14567 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14568 | EXPECT_EQ("hello world", response_data); |
| 14569 | |
| 14570 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14571 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14572 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14573 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14574 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14575 | // immediate server closing of the socket. |
| 14576 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14577 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14578 | HttpRequestInfo request; |
| 14579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14580 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14581 | request.traffic_annotation = |
| 14582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14583 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14584 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14585 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14586 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14587 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14588 | spdy::SpdySerializedFrame req( |
| 14589 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14590 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14591 | |
| 14592 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14593 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14594 | }; |
| 14595 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14596 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14597 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14599 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14606 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14607 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14608 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14609 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14610 | // it gets it. This is needed since the auth handler may get destroyed |
| 14611 | // before we get a chance to query it. |
| 14612 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14613 | public: |
| 14614 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14615 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14616 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14617 | |
| 14618 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14619 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14620 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14621 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14622 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14623 | *url_ = request->url; |
| 14624 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14625 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14626 | } |
| 14627 | |
| 14628 | private: |
| 14629 | GURL* url_; |
| 14630 | }; |
| 14631 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14632 | // Test that if we cancel the transaction as the connection is completing, that |
| 14633 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14634 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14635 | // Setup everything about the connection to complete synchronously, so that |
| 14636 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14637 | // for is the callback from the HttpStreamRequest. |
| 14638 | // Then cancel the transaction. |
| 14639 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14640 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14641 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14642 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14643 | MockRead(SYNCHRONOUS, "hello world"), |
| 14644 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14645 | }; |
| 14646 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14647 | HttpRequestInfo request; |
| 14648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14649 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14650 | request.traffic_annotation = |
| 14651 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14652 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14654 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14655 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14656 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14657 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14658 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14659 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14661 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14662 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14663 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14664 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14666 | trans.reset(); // Cancel the transaction here. |
| 14667 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14668 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14669 | } |
| 14670 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14671 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14672 | // stream is drained properly and added back to the socket pool. The main |
| 14673 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14674 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14675 | // deleted. |
| 14676 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14677 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14678 | MockRead data_reads[] = { |
| 14679 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14680 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14681 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14682 | MockRead(ASYNC, "1"), |
| 14683 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14684 | // HttpNetworkTransaction has been deleted. |
| 14685 | MockRead(ASYNC, "2"), |
| 14686 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14687 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14688 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14692 | |
| 14693 | { |
| 14694 | HttpRequestInfo request; |
| 14695 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14696 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14697 | request.traffic_annotation = |
| 14698 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14699 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14701 | TestCompletionCallback callback; |
| 14702 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14703 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14705 | callback.WaitForResult(); |
| 14706 | |
| 14707 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14708 | ASSERT_TRUE(response); |
| 14709 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14710 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14711 | |
| 14712 | // The transaction and HttpRequestInfo are deleted. |
| 14713 | } |
| 14714 | |
| 14715 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14716 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14717 | |
| 14718 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14719 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14720 | } |
| 14721 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14722 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14723 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14724 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14725 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14726 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14727 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14728 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14730 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14731 | HttpRequestInfo request; |
| 14732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14733 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14734 | request.traffic_annotation = |
| 14735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14736 | |
| 14737 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14738 | MockWrite( |
| 14739 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14740 | "Host: www.example.org\r\n" |
| 14741 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14742 | }; |
| 14743 | |
| 14744 | MockRead data_reads1[] = { |
| 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] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14753 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14754 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14756 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14757 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14758 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14759 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14760 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14762 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14764 | |
| 14765 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14766 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14768 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14769 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14770 | |
| 14771 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14772 | EXPECT_EQ(200, response->headers->response_code()); |
| 14773 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14774 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14775 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14776 | HostPortPair::FromString("myproxy:70")), |
| 14777 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14778 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14779 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14780 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14781 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14782 | |
| 14783 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14784 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14785 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14786 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14787 | } |
| 14788 | |
| 14789 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14790 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14791 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14792 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14793 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14794 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14795 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14797 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14798 | HttpRequestInfo request; |
| 14799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14800 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14801 | request.traffic_annotation = |
| 14802 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14803 | |
| 14804 | // Since we have proxy, should try to establish tunnel. |
| 14805 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14806 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14807 | "Host: www.example.org:443\r\n" |
| 14808 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14809 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14810 | MockWrite("GET / HTTP/1.1\r\n" |
| 14811 | "Host: www.example.org\r\n" |
| 14812 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14813 | }; |
| 14814 | |
| 14815 | MockRead data_reads1[] = { |
| 14816 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14817 | |
| 14818 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14819 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14820 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14821 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14822 | }; |
| 14823 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14824 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14825 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14826 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14827 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14829 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14832 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14833 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14834 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14835 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14837 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14839 | |
| 14840 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14841 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14842 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14843 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14844 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14845 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14846 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14847 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14848 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14849 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14850 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14852 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14853 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14854 | |
| 14855 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14856 | EXPECT_EQ(200, response->headers->response_code()); |
| 14857 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14858 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14859 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14860 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14861 | HostPortPair::FromString("myproxy:70")), |
| 14862 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14863 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14864 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14865 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14866 | |
| 14867 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14868 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14869 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14870 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14871 | } |
| 14872 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14873 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14874 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14875 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14876 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14877 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14878 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14879 | BoundTestNetLog log; |
| 14880 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14882 | |
| 14883 | HttpRequestInfo request; |
| 14884 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14885 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14886 | request.traffic_annotation = |
| 14887 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14888 | |
| 14889 | // Since we have proxy, should try to establish tunnel. |
| 14890 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14891 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14892 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14893 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14894 | |
| 14895 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14896 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14897 | "Connection: keep-alive\r\n\r\n"), |
| 14898 | }; |
| 14899 | |
| 14900 | MockRead data_reads1[] = { |
| 14901 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14902 | |
| 14903 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14904 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14905 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14906 | MockRead(SYNCHRONOUS, OK), |
| 14907 | }; |
| 14908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14909 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14910 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14911 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14913 | |
| 14914 | TestCompletionCallback callback1; |
| 14915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [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)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14920 | |
| 14921 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14922 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14923 | TestNetLogEntry::List entries; |
| 14924 | log.GetEntries(&entries); |
| 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); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14928 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14929 | entries, pos, |
| 14930 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14931 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14933 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14934 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14935 | |
| 14936 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14937 | EXPECT_EQ(200, response->headers->response_code()); |
| 14938 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14939 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14940 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14941 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14942 | HostPortPair::FromString("myproxy:70")), |
| 14943 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14944 | |
| 14945 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14946 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14947 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14948 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14949 | } |
| 14950 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14951 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14952 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14953 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14954 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14955 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14956 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14957 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14959 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14960 | HttpRequestInfo request; |
| 14961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14962 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14963 | request.traffic_annotation = |
| 14964 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14965 | |
| 14966 | // Since we have proxy, should try to establish tunnel. |
| 14967 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14968 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14969 | "Host: www.example.org:443\r\n" |
| 14970 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14971 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14972 | MockWrite("GET / HTTP/1.1\r\n" |
| 14973 | "Host: www.example.org\r\n" |
| 14974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14975 | }; |
| 14976 | |
| 14977 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14978 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14979 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14980 | }; |
| 14981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14982 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14983 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14984 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14987 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14989 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14991 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14993 | |
| 14994 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14995 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14996 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14997 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14998 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14999 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15000 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15001 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15002 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15003 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15004 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15005 | } |
| 15006 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15007 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15008 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15009 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15010 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15011 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15012 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15013 | spdy::SpdySerializedFrame resp( |
| 15014 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15015 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15016 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15017 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15018 | }; |
| 15019 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15020 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15021 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15022 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15023 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15024 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15025 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15028 | |
| 15029 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15030 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15031 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15032 | PRIVACY_MODE_DISABLED, |
| 15033 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15034 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15035 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15036 | |
| 15037 | HttpRequestInfo request; |
| 15038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15039 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15040 | request.traffic_annotation = |
| 15041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15043 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15044 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15045 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15046 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15047 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15048 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15049 | } |
| 15050 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15051 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15052 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15053 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15054 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15055 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15056 | request_info.url = GURL("https://www.example.com/"); |
| 15057 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15058 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15059 | request_info.traffic_annotation = |
| 15060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15061 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15062 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15063 | MockWrite data_writes[] = { |
| 15064 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15065 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15066 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15073 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15074 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15075 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15076 | rv = callback.WaitForResult(); |
| 15077 | ASSERT_EQ(error, rv); |
| 15078 | } |
| 15079 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15080 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15081 | // Just check a grab bag of cert errors. |
| 15082 | static const int kErrors[] = { |
| 15083 | ERR_CERT_COMMON_NAME_INVALID, |
| 15084 | ERR_CERT_AUTHORITY_INVALID, |
| 15085 | ERR_CERT_DATE_INVALID, |
| 15086 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15087 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15088 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15089 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15090 | } |
| 15091 | } |
| 15092 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15093 | // Ensure that a client certificate is removed from the SSL client auth |
| 15094 | // cache when: |
| 15095 | // 1) No proxy is involved. |
| 15096 | // 2) TLS False Start is disabled. |
| 15097 | // 3) The initial TLS handshake requests a client certificate. |
| 15098 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15099 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15100 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15101 | request_info.url = GURL("https://www.example.com/"); |
| 15102 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15103 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15104 | request_info.traffic_annotation = |
| 15105 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15106 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15107 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15108 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15109 | |
| 15110 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15111 | // CertificateRequest is received for the first time, the handshake will |
| 15112 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15113 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15114 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15116 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15117 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15118 | |
| 15119 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15120 | // False Start is not being used, the result of the SSL handshake will be |
| 15121 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15122 | // matches the result of a server sending a handshake_failure alert, |
| 15123 | // rather than a Finished message, because it requires a client |
| 15124 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15125 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15126 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15128 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15129 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15130 | |
| 15131 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15132 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15133 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15134 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15135 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15136 | // requiring a client certificate, this fallback handshake should also |
| 15137 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15138 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15139 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15140 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15142 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15143 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15144 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15145 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15146 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15147 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15148 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15149 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15150 | // requiring a client certificate, this fallback handshake should also |
| 15151 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15152 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15153 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15155 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15156 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15160 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15161 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15162 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15163 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15164 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15165 | |
| 15166 | // Complete the SSL handshake, which should abort due to requiring a |
| 15167 | // client certificate. |
| 15168 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15169 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15170 | |
| 15171 | // Indicate that no certificate should be supplied. From the perspective |
| 15172 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15173 | // certificate, so this is the same as supply a |
| 15174 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15175 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15176 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15177 | |
| 15178 | // Ensure the certificate was added to the client auth cache before |
| 15179 | // allowing the connection to continue restarting. |
| 15180 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15181 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15182 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15183 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15184 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15185 | |
| 15186 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15187 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15188 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15189 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15190 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15191 | |
| 15192 | // Ensure that the client certificate is removed from the cache on a |
| 15193 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15194 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15195 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15196 | } |
| 15197 | |
| 15198 | // Ensure that a client certificate is removed from the SSL client auth |
| 15199 | // cache when: |
| 15200 | // 1) No proxy is involved. |
| 15201 | // 2) TLS False Start is enabled. |
| 15202 | // 3) The initial TLS handshake requests a client certificate. |
| 15203 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15204 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15205 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15206 | request_info.url = GURL("https://www.example.com/"); |
| 15207 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15208 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15209 | request_info.traffic_annotation = |
| 15210 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15211 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15212 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15213 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15214 | |
| 15215 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15216 | // return successfully after reading up to the peer's Certificate message. |
| 15217 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15218 | // enqueue application data to be sent in the same packet as the |
| 15219 | // ChangeCipherSpec and Finished messages. |
| 15220 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15221 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15222 | // Finished messages. If there was an error negotiating with the peer, |
| 15223 | // such as due to the peer requiring a client certificate when none was |
| 15224 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15225 | // called. |
| 15226 | |
| 15227 | // Like the non-False Start case, when a client certificate is requested by |
| 15228 | // the peer, the handshake is aborted during the Connect() call. |
| 15229 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15230 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15231 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15233 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15234 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15235 | |
| 15236 | // When a client certificate is supplied, Connect() will not be aborted |
| 15237 | // when the peer requests the certificate. Instead, the handshake will |
| 15238 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15239 | // the socket. The handshake messages are not processed until Read() is |
| 15240 | // called, which then detects that the handshake was aborted, due to the |
| 15241 | // peer sending a handshake_failure because it requires a client |
| 15242 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15243 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15244 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15246 | MockRead data2_reads[] = { |
| 15247 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15248 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15249 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15250 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15251 | |
| 15252 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15253 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15254 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15255 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15256 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15258 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15259 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15260 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15261 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15262 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15263 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15264 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15266 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15267 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15268 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15269 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15270 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15271 | ssl_data5.cert_request_info = cert_request.get(); |
| 15272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15273 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15274 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15275 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15278 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15279 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15280 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15281 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15282 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15283 | |
| 15284 | // Complete the SSL handshake, which should abort due to requiring a |
| 15285 | // client certificate. |
| 15286 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15287 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15288 | |
| 15289 | // Indicate that no certificate should be supplied. From the perspective |
| 15290 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15291 | // certificate, so this is the same as supply a |
| 15292 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15293 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15294 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15295 | |
| 15296 | // Ensure the certificate was added to the client auth cache before |
| 15297 | // allowing the connection to continue restarting. |
| 15298 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15299 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15300 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15301 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15302 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15303 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15304 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15305 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15306 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15308 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15309 | |
| 15310 | // Ensure that the client certificate is removed from the cache on a |
| 15311 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15312 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15313 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15314 | } |
| 15315 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15316 | // Ensure that a client certificate is removed from the SSL client auth |
| 15317 | // cache when: |
| 15318 | // 1) An HTTPS proxy is involved. |
| 15319 | // 3) The HTTPS proxy requests a client certificate. |
| 15320 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15321 | // proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15322 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15323 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15324 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15325 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15326 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15327 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15328 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15329 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15330 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15331 | // Repeat the test for connecting to an HTTPS endpoint, then for connecting to |
| 15332 | // an HTTP endpoint. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15333 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15334 | requests[0].url = GURL("https://www.example.com/"); |
| 15335 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15336 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15337 | requests[0].traffic_annotation = |
| 15338 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15339 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15340 | // HTTPS requests are tunneled. |
| 15341 | MockWrite https_writes[] = { |
| 15342 | MockWrite("CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 15343 | "Host: www.example.com:443\r\n" |
| 15344 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15345 | }; |
| 15346 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15347 | requests[1].url = GURL("http://www.example.com/"); |
| 15348 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15349 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15350 | requests[1].traffic_annotation = |
| 15351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15352 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15353 | // HTTP requests are not. |
| 15354 | MockWrite http_writes[] = { |
| 15355 | MockWrite("GET http://www.example.com/ HTTP/1.1\r\n" |
| 15356 | "Host: www.example.com\r\n" |
| 15357 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15358 | }; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15359 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15360 | // When the server rejects the client certificate, it will close the |
| 15361 | // connection. In TLS 1.2, this is signaled out of Connect(). In TLS 1.3 (or |
| 15362 | // TLS 1.2 with False Start), the error is returned out of the first Read(). |
| 15363 | for (bool reject_in_connect : {true, false}) { |
| 15364 | SCOPED_TRACE(reject_in_connect); |
| 15365 | // Client certificate errors are typically signaled with |
| 15366 | // ERR_BAD_SSL_CLIENT_AUTH_CERT, but sometimes the server gives an arbitrary |
| 15367 | // protocol error. |
| 15368 | for (Error reject_error : |
| 15369 | {ERR_SSL_PROTOCOL_ERROR, ERR_BAD_SSL_CLIENT_AUTH_CERT}) { |
| 15370 | SCOPED_TRACE(reject_error); |
| 15371 | // Tunneled and non-tunneled requests are handled differently. Test both. |
| 15372 | for (const HttpRequestInfo& request : requests) { |
| 15373 | SCOPED_TRACE(request.url); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15374 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15375 | session_deps_.socket_factory = |
| 15376 | std::make_unique<MockClientSocketFactory>(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15377 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15378 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15379 | // [ssl_]data[1-2]. [ssl_]data3 is not needed because we do not retry |
| 15380 | // for proxies. Rather than represending the endpoint |
| 15381 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15382 | // (proxy:70). |
| 15383 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 15384 | ssl_data1.cert_request_info = cert_request.get(); |
| 15385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15386 | StaticSocketDataProvider data1; |
| 15387 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15388 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15389 | base::Optional<SSLSocketDataProvider> ssl_data2; |
| 15390 | base::Optional<StaticSocketDataProvider> data2; |
| 15391 | MockRead error_in_read[] = {MockRead(ASYNC, reject_error)}; |
| 15392 | if (reject_in_connect) { |
| 15393 | ssl_data2.emplace(ASYNC, reject_error); |
| 15394 | // There are no reads or writes. |
| 15395 | data2.emplace(); |
| 15396 | } else { |
| 15397 | ssl_data2.emplace(ASYNC, OK); |
| 15398 | // We will get one Write() in before observing the error in Read(). |
| 15399 | if (request.url.SchemeIsCryptographic()) { |
| 15400 | data2.emplace(error_in_read, https_writes); |
| 15401 | } else { |
| 15402 | data2.emplace(error_in_read, http_writes); |
| 15403 | } |
| 15404 | } |
| 15405 | ssl_data2->cert_request_info = cert_request.get(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15406 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15407 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 15408 | &ssl_data2.value()); |
| 15409 | session_deps_.socket_factory->AddSocketDataProvider(&data2.value()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15410 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15411 | std::unique_ptr<HttpNetworkSession> session = |
| 15412 | CreateSession(&session_deps_); |
| 15413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15414 | |
| 15415 | // Begin the SSL handshake with the proxy. |
| 15416 | TestCompletionCallback callback; |
| 15417 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 15418 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15419 | |
| 15420 | // Complete the SSL handshake, which should abort due to requiring a |
| 15421 | // client certificate. |
| 15422 | rv = callback.WaitForResult(); |
| 15423 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15424 | |
| 15425 | // Indicate that no certificate should be supplied. From the |
| 15426 | // perspective of SSLClientCertCache, NULL is just as meaningful as a |
| 15427 | // real certificate, so this is the same as supply a |
| 15428 | // legitimate-but-unacceptable certificate. |
| 15429 | rv = |
| 15430 | trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
| 15431 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15432 | |
| 15433 | // Ensure the certificate was added to the client auth cache before |
| 15434 | // allowing the connection to continue restarting. |
| 15435 | scoped_refptr<X509Certificate> client_cert; |
| 15436 | scoped_refptr<SSLPrivateKey> client_private_key; |
| 15437 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 15438 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 15439 | ASSERT_FALSE(client_cert); |
| 15440 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15441 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
| 15442 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 15443 | HostPortPair("www.example.com", 443), &client_cert, |
| 15444 | &client_private_key)); |
| 15445 | |
| 15446 | // Restart the handshake. This will consume ssl_data2. The result code |
| 15447 | // is checked against what ssl_data2 should return. |
| 15448 | rv = callback.WaitForResult(); |
| 15449 | ASSERT_THAT(rv, AnyOf(IsError(ERR_PROXY_CONNECTION_FAILED), |
| 15450 | IsError(reject_error))); |
| 15451 | |
| 15452 | // Now that the new handshake has failed, ensure that the client |
| 15453 | // certificate was removed from the client auth cache. |
| 15454 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 15455 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 15456 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 15457 | HostPortPair("www.example.com", 443), &client_cert, |
| 15458 | &client_private_key)); |
| 15459 | } |
| 15460 | } |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15461 | } |
| 15462 | } |
| 15463 | |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15464 | // Test that HttpNetworkTransaction correctly handles (mocked) certificate |
| 15465 | // requests during a TLS renegotiation. |
| 15466 | TEST_F(HttpNetworkTransactionTest, CertificateRequestInRenego) { |
| 15467 | HttpRequestInfo request_info; |
| 15468 | request_info.url = GURL("https://www.example.com/"); |
| 15469 | request_info.method = "GET"; |
| 15470 | request_info.load_flags = LOAD_NORMAL; |
| 15471 | request_info.traffic_annotation = |
| 15472 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 15473 | |
| 15474 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 15475 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
| 15476 | |
| 15477 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 15478 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 15479 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 15480 | ASSERT_TRUE(identity); |
| 15481 | |
| 15482 | // The first connection's handshake succeeds, but we get |
| 15483 | // ERR_SSL_CLIENT_AUTH_CERT_NEEDED instead of an HTTP response. |
| 15484 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 15485 | ssl_data1.cert_request_info = cert_request.get(); |
| 15486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15487 | MockWrite data1_writes[] = { |
| 15488 | MockWrite("GET / HTTP/1.1\r\n" |
| 15489 | "Host: www.example.com\r\n" |
| 15490 | "Connection: keep-alive\r\n\r\n"), |
| 15491 | }; |
| 15492 | MockRead data1_reads[] = { |
| 15493 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED), |
| 15494 | }; |
| 15495 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 15496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15497 | |
| 15498 | // After supplying with certificate, we restart the request from the top, |
| 15499 | // which succeeds this time. |
| 15500 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 15501 | ssl_data2.expected_send_client_cert = true; |
| 15502 | ssl_data2.expected_client_cert = identity->certificate(); |
| 15503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 15504 | MockWrite data2_writes[] = { |
| 15505 | MockWrite("GET / HTTP/1.1\r\n" |
| 15506 | "Host: www.example.com\r\n" |
| 15507 | "Connection: keep-alive\r\n\r\n"), |
| 15508 | }; |
| 15509 | MockRead data2_reads[] = { |
| 15510 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15511 | "Content-Length: 0\r\n\r\n"), |
| 15512 | }; |
| 15513 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 15514 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15515 | |
| 15516 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 15517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15518 | |
| 15519 | TestCompletionCallback callback; |
| 15520 | int rv = callback.GetResult( |
| 15521 | trans.Start(&request_info, callback.callback(), NetLogWithSource())); |
| 15522 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15523 | |
| 15524 | rv = trans.RestartWithCertificate(identity->certificate(), |
| 15525 | identity->ssl_private_key(), |
| 15526 | callback.callback()); |
| 15527 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15528 | |
| 15529 | // Ensure the certificate was added to the client auth cache |
| 15530 | // allowing the connection to continue restarting. |
| 15531 | scoped_refptr<X509Certificate> client_cert; |
| 15532 | scoped_refptr<SSLPrivateKey> client_private_key; |
| 15533 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 15534 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 15535 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 15536 | |
| 15537 | // Complete the handshake. The request now succeeds. |
| 15538 | rv = callback.WaitForResult(); |
| 15539 | ASSERT_THAT(rv, IsError(OK)); |
| 15540 | EXPECT_EQ(200, trans.GetResponseInfo()->headers->response_code()); |
| 15541 | |
| 15542 | // The client certificate remains in the cache. |
| 15543 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 15544 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 15545 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 15546 | } |
| 15547 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15548 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15549 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15550 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15551 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15552 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15553 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15554 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15555 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15556 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15557 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15558 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15559 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15560 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15561 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15562 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15563 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15564 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15565 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15566 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15567 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15568 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15569 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15570 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15571 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15572 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15573 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15574 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15575 | }; |
| 15576 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15577 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15578 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15579 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15580 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15581 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15582 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15583 | HttpRequestInfo request1; |
| 15584 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15585 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15586 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15587 | request1.traffic_annotation = |
| 15588 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15589 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15590 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15591 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15593 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15594 | |
| 15595 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15596 | ASSERT_TRUE(response); |
| 15597 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15598 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15599 | |
| 15600 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15601 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15602 | EXPECT_EQ("hello!", response_data); |
| 15603 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15604 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15605 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15606 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15607 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15608 | |
| 15609 | HttpRequestInfo request2; |
| 15610 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15611 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15612 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15613 | request2.traffic_annotation = |
| 15614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15615 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15616 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15617 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15619 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15620 | |
| 15621 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15622 | ASSERT_TRUE(response); |
| 15623 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15624 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15625 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15626 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15627 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15628 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15629 | } |
| 15630 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15631 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15632 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15633 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15635 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15636 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15637 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15638 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15639 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15640 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15641 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15642 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15643 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15644 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15645 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15646 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15647 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15648 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15649 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15650 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15651 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15652 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15653 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15654 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15655 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15656 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15657 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15658 | }; |
| 15659 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15660 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15661 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15662 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15663 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15664 | |
| 15665 | TestCompletionCallback callback; |
| 15666 | HttpRequestInfo request1; |
| 15667 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15668 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15669 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15670 | request1.traffic_annotation = |
| 15671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15672 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15674 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15676 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15677 | |
| 15678 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15679 | ASSERT_TRUE(response); |
| 15680 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15681 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15682 | |
| 15683 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15684 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15685 | EXPECT_EQ("hello!", response_data); |
| 15686 | |
| 15687 | HttpRequestInfo request2; |
| 15688 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15689 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15690 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15691 | request2.traffic_annotation = |
| 15692 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15693 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15695 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15697 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15698 | |
| 15699 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15700 | ASSERT_TRUE(response); |
| 15701 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15702 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15703 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15704 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15705 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15706 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15707 | } |
| 15708 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15709 | // Regression test for https://crbug.com/546991. |
| 15710 | // The server might not be able to serve an IP pooled request, and might send a |
| 15711 | // 421 Misdirected Request response status to indicate this. |
| 15712 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15713 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15714 | // Two hosts resolve to the same IP address. |
| 15715 | const std::string ip_addr = "1.2.3.4"; |
| 15716 | IPAddress ip; |
| 15717 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15718 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15719 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15720 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15721 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15722 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15723 | |
| 15724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15725 | |
| 15726 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15727 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15728 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15729 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15730 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15731 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15732 | spdy::SpdySerializedFrame rst( |
| 15733 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15734 | MockWrite writes1[] = { |
| 15735 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15736 | CreateMockWrite(rst, 6), |
| 15737 | }; |
| 15738 | |
| 15739 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15740 | spdy::SpdySerializedFrame resp1( |
| 15741 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15742 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15743 | spdy::SpdyHeaderBlock response_headers; |
| 15744 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15745 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15746 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15747 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15748 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15749 | |
| 15750 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15751 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15753 | |
| 15754 | AddSSLSocketData(); |
| 15755 | |
| 15756 | // Retry the second request on a second connection. |
| 15757 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15758 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15759 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15760 | MockWrite writes2[] = { |
| 15761 | CreateMockWrite(req3, 0), |
| 15762 | }; |
| 15763 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15764 | spdy::SpdySerializedFrame resp3( |
| 15765 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15766 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15767 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15768 | MockRead(ASYNC, 0, 3)}; |
| 15769 | |
| 15770 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15771 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15772 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15773 | |
| 15774 | AddSSLSocketData(); |
| 15775 | |
| 15776 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15777 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15778 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15779 | EXPECT_THAT(rv, IsOk()); |
| 15780 | |
| 15781 | HttpRequestInfo request1; |
| 15782 | request1.method = "GET"; |
| 15783 | request1.url = GURL("https://www.example.org/"); |
| 15784 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15785 | request1.traffic_annotation = |
| 15786 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15787 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15788 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15789 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15790 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15792 | rv = callback.WaitForResult(); |
| 15793 | EXPECT_THAT(rv, IsOk()); |
| 15794 | |
| 15795 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15796 | ASSERT_TRUE(response); |
| 15797 | ASSERT_TRUE(response->headers); |
| 15798 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15799 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15800 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15801 | std::string response_data; |
| 15802 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15803 | EXPECT_EQ("hello!", response_data); |
| 15804 | |
| 15805 | HttpRequestInfo request2; |
| 15806 | request2.method = "GET"; |
| 15807 | request2.url = GURL("https://mail.example.org/"); |
| 15808 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15809 | request2.traffic_annotation = |
| 15810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15811 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15812 | |
| 15813 | BoundTestNetLog log; |
| 15814 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15816 | rv = callback.WaitForResult(); |
| 15817 | EXPECT_THAT(rv, IsOk()); |
| 15818 | |
| 15819 | response = trans2.GetResponseInfo(); |
| 15820 | ASSERT_TRUE(response); |
| 15821 | ASSERT_TRUE(response->headers); |
| 15822 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15823 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15824 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15825 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15826 | EXPECT_EQ("hello!", response_data); |
| 15827 | |
| 15828 | TestNetLogEntry::List entries; |
| 15829 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15830 | ExpectLogContainsSomewhere( |
| 15831 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15832 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15833 | } |
| 15834 | |
| 15835 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15836 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15837 | // portions of the response. |
| 15838 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15839 | // Two hosts resolve to the same IP address. |
| 15840 | const std::string ip_addr = "1.2.3.4"; |
| 15841 | IPAddress ip; |
| 15842 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15843 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15844 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15845 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15846 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15847 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15848 | |
| 15849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15850 | |
| 15851 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15852 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15853 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15854 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15855 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15856 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15857 | spdy::SpdySerializedFrame rst( |
| 15858 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15859 | MockWrite writes1[] = { |
| 15860 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15861 | CreateMockWrite(rst, 6), |
| 15862 | }; |
| 15863 | |
| 15864 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15865 | spdy::SpdySerializedFrame resp1( |
| 15866 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15867 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15868 | spdy::SpdyHeaderBlock response_headers; |
| 15869 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15870 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15871 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15872 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15873 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15874 | |
| 15875 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15876 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15878 | |
| 15879 | AddSSLSocketData(); |
| 15880 | |
| 15881 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15882 | // Retry again. |
| 15883 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15884 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15885 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15886 | MockWrite writes2[] = { |
| 15887 | CreateMockWrite(req3, 0), |
| 15888 | }; |
| 15889 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15890 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15891 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15892 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15893 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15894 | MockRead(ASYNC, 0, 3)}; |
| 15895 | |
| 15896 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15897 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15898 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15899 | |
| 15900 | AddSSLSocketData(); |
| 15901 | |
| 15902 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15903 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15904 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15905 | EXPECT_THAT(rv, IsOk()); |
| 15906 | |
| 15907 | HttpRequestInfo request1; |
| 15908 | request1.method = "GET"; |
| 15909 | request1.url = GURL("https://www.example.org/"); |
| 15910 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15911 | request1.traffic_annotation = |
| 15912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15913 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15914 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15915 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15916 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15918 | rv = callback.WaitForResult(); |
| 15919 | EXPECT_THAT(rv, IsOk()); |
| 15920 | |
| 15921 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15922 | ASSERT_TRUE(response); |
| 15923 | ASSERT_TRUE(response->headers); |
| 15924 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15925 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15926 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15927 | std::string response_data; |
| 15928 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15929 | EXPECT_EQ("hello!", response_data); |
| 15930 | |
| 15931 | HttpRequestInfo request2; |
| 15932 | request2.method = "GET"; |
| 15933 | request2.url = GURL("https://mail.example.org/"); |
| 15934 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15935 | request2.traffic_annotation = |
| 15936 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15937 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15938 | |
| 15939 | BoundTestNetLog log; |
| 15940 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15942 | rv = callback.WaitForResult(); |
| 15943 | EXPECT_THAT(rv, IsOk()); |
| 15944 | |
| 15945 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15946 | // caller. |
| 15947 | response = trans2.GetResponseInfo(); |
| 15948 | ASSERT_TRUE(response); |
| 15949 | ASSERT_TRUE(response->headers); |
| 15950 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15951 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15952 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15953 | EXPECT_TRUE(response->ssl_info.cert); |
| 15954 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15955 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15956 | } |
| 15957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15958 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15959 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15960 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15961 | session_deps_.host_resolver = |
| 15962 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15963 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15964 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15965 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15966 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15967 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15968 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15969 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15970 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15971 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15972 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15973 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15974 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15975 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15976 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15977 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15978 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15979 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15980 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15981 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15982 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15983 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15984 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15985 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15986 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15987 | }; |
| 15988 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15989 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15990 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15991 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15992 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15993 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15994 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15995 | HttpRequestInfo request1; |
| 15996 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15997 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15998 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15999 | request1.traffic_annotation = |
| 16000 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16001 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16003 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16005 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16006 | |
| 16007 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16008 | ASSERT_TRUE(response); |
| 16009 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16010 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16011 | |
| 16012 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16013 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16014 | EXPECT_EQ("hello!", response_data); |
| 16015 | |
| 16016 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16017 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 16018 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16019 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16020 | |
| 16021 | HttpRequestInfo request2; |
| 16022 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16023 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16024 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16025 | request2.traffic_annotation = |
| 16026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16027 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16028 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16029 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16031 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16032 | |
| 16033 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16034 | ASSERT_TRUE(response); |
| 16035 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16036 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16037 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16038 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16039 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16040 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16041 | } |
| 16042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16043 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16044 | const std::string https_url = "https://www.example.org:8080/"; |
| 16045 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16046 | |
| 16047 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16048 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16049 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16050 | |
| 16051 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16052 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16053 | }; |
| 16054 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16055 | spdy::SpdySerializedFrame resp1( |
| 16056 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16057 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16058 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16059 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16061 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16062 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16063 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16064 | |
| 16065 | // HTTP GET for the HTTP URL |
| 16066 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16067 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16068 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16069 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16070 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16071 | }; |
| 16072 | |
| 16073 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16074 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16075 | MockRead(ASYNC, 2, "hello"), |
| 16076 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16077 | }; |
| 16078 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16079 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16080 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16081 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16082 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16084 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16085 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16088 | |
| 16089 | // Start the first transaction to set up the SpdySession |
| 16090 | HttpRequestInfo request1; |
| 16091 | request1.method = "GET"; |
| 16092 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16093 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16094 | request1.traffic_annotation = |
| 16095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16096 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16097 | TestCompletionCallback callback1; |
| 16098 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16099 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16100 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16101 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16102 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16103 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16104 | |
| 16105 | // Now, start the HTTP request |
| 16106 | HttpRequestInfo request2; |
| 16107 | request2.method = "GET"; |
| 16108 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16109 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16110 | request2.traffic_annotation = |
| 16111 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16112 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16113 | TestCompletionCallback callback2; |
| 16114 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16115 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16116 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16117 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16118 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16119 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16120 | } |
| 16121 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16122 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16123 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16124 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16125 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16126 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16127 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16128 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16129 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16130 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16132 | |
| 16133 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16134 | // negotiated. |
| 16135 | StaticSocketDataProvider data; |
| 16136 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16137 | |
| 16138 | // 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] | 16139 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16140 | // mocked. This way the request relies on the alternate Job. |
| 16141 | StaticSocketDataProvider data_refused; |
| 16142 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16143 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16144 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16145 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16147 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16148 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16149 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16150 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16151 | http_server_properties->SetHttp2AlternativeService( |
| 16152 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16153 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16154 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16156 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16157 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16158 | request.traffic_annotation = |
| 16159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16160 | TestCompletionCallback callback; |
| 16161 | |
| 16162 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16163 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16164 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16165 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16166 | } |
| 16167 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16168 | // 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] | 16169 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16170 | // succeeds, the request should succeed, even if the latter fails because |
| 16171 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16172 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16173 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16174 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16175 | |
| 16176 | // Negotiate HTTP/1.1 with alternative. |
| 16177 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16178 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16179 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16180 | |
| 16181 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16182 | // negotiated. |
| 16183 | StaticSocketDataProvider data; |
| 16184 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16185 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16186 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16187 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16188 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16189 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16190 | |
| 16191 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16192 | MockWrite("GET / HTTP/1.1\r\n" |
| 16193 | "Host: www.example.org\r\n" |
| 16194 | "Connection: keep-alive\r\n\r\n"), |
| 16195 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16196 | "Host: www.example.org\r\n" |
| 16197 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16198 | }; |
| 16199 | |
| 16200 | MockRead http_reads[] = { |
| 16201 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16202 | MockRead("Content-Type: text/html\r\n"), |
| 16203 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16204 | MockRead("foobar"), |
| 16205 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16206 | MockRead("Content-Type: text/html\r\n"), |
| 16207 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16208 | MockRead("another"), |
| 16209 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16210 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16211 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16212 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16213 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16215 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16216 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16217 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16218 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16219 | http_server_properties->SetHttp2AlternativeService( |
| 16220 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16221 | |
| 16222 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16223 | HttpRequestInfo request1; |
| 16224 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16225 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16226 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16227 | request1.traffic_annotation = |
| 16228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16229 | TestCompletionCallback callback1; |
| 16230 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16231 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16232 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16233 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16234 | |
| 16235 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16236 | ASSERT_TRUE(response1); |
| 16237 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16238 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16239 | |
| 16240 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16241 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16242 | EXPECT_EQ("foobar", response_data1); |
| 16243 | |
| 16244 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16245 | // for alternative service. |
| 16246 | EXPECT_TRUE( |
| 16247 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16248 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16249 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16250 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16251 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16252 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16253 | HttpRequestInfo request2; |
| 16254 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16255 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16256 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16257 | request2.traffic_annotation = |
| 16258 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16259 | TestCompletionCallback callback2; |
| 16260 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16261 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16262 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16263 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16264 | |
| 16265 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16266 | ASSERT_TRUE(response2); |
| 16267 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16268 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16269 | |
| 16270 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16271 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16272 | EXPECT_EQ("another", response_data2); |
| 16273 | } |
| 16274 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16275 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16276 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16277 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16278 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16279 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16280 | HostPortPair alternative("alternative.example.org", 443); |
| 16281 | std::string origin_url = "https://origin.example.org:443"; |
| 16282 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16283 | |
| 16284 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16285 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16286 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16287 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16288 | |
| 16289 | // HTTP/1.1 data for |request1| and |request2|. |
| 16290 | MockWrite http_writes[] = { |
| 16291 | MockWrite( |
| 16292 | "GET / HTTP/1.1\r\n" |
| 16293 | "Host: alternative.example.org\r\n" |
| 16294 | "Connection: keep-alive\r\n\r\n"), |
| 16295 | MockWrite( |
| 16296 | "GET / HTTP/1.1\r\n" |
| 16297 | "Host: alternative.example.org\r\n" |
| 16298 | "Connection: keep-alive\r\n\r\n"), |
| 16299 | }; |
| 16300 | |
| 16301 | MockRead http_reads[] = { |
| 16302 | MockRead( |
| 16303 | "HTTP/1.1 200 OK\r\n" |
| 16304 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16305 | "Content-Length: 40\r\n\r\n" |
| 16306 | "first HTTP/1.1 response from alternative"), |
| 16307 | MockRead( |
| 16308 | "HTTP/1.1 200 OK\r\n" |
| 16309 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16310 | "Content-Length: 41\r\n\r\n" |
| 16311 | "second HTTP/1.1 response from alternative"), |
| 16312 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16313 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16314 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16315 | |
| 16316 | // This test documents that an alternate Job should not pool to an already |
| 16317 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16318 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16319 | StaticSocketDataProvider data_refused; |
| 16320 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16321 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16322 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16323 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16325 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16326 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16327 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16328 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16329 | http_server_properties->SetHttp2AlternativeService( |
| 16330 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16331 | |
| 16332 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16333 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16334 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16335 | request1.method = "GET"; |
| 16336 | request1.url = GURL(alternative_url); |
| 16337 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16338 | request1.traffic_annotation = |
| 16339 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16340 | TestCompletionCallback callback1; |
| 16341 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16342 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16343 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16344 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16345 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16346 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16347 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16348 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16349 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16350 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16351 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16352 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16353 | |
| 16354 | // Request for origin.example.org, which has an alternative service. This |
| 16355 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16356 | // 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] | 16357 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16358 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16359 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16360 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16361 | request2.method = "GET"; |
| 16362 | request2.url = GURL(origin_url); |
| 16363 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16364 | request2.traffic_annotation = |
| 16365 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16366 | TestCompletionCallback callback2; |
| 16367 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16368 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16369 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16370 | |
| 16371 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16372 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16373 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16374 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16375 | request3.method = "GET"; |
| 16376 | request3.url = GURL(alternative_url); |
| 16377 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16378 | request3.traffic_annotation = |
| 16379 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16380 | TestCompletionCallback callback3; |
| 16381 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16382 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16383 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16384 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16385 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16386 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16387 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16388 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16389 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16390 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16391 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16392 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16393 | } |
| 16394 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16395 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16396 | const std::string https_url = "https://www.example.org:8080/"; |
| 16397 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16398 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16399 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16400 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16401 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16402 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16403 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16404 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16405 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16406 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16407 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16408 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16409 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16410 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16411 | |
| 16412 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16413 | spdy::SpdyHeaderBlock req2_block; |
| 16414 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16415 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16416 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16417 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16418 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16419 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16420 | |
| 16421 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16422 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16423 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16424 | }; |
| 16425 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16426 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16427 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16428 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16429 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16430 | spdy::SpdySerializedFrame body1( |
| 16431 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16432 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16433 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16434 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16435 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16436 | spdy::SpdySerializedFrame resp2( |
| 16437 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16438 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16439 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16440 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16441 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16442 | CreateMockRead(wrapped_resp1, 4), |
| 16443 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16444 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16445 | CreateMockRead(resp2, 8), |
| 16446 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16447 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16448 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16449 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16450 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16451 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16452 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16453 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16454 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16455 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16456 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16457 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16458 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16459 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16460 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16462 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16463 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16464 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16465 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16466 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16467 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16468 | |
| 16469 | // Start the first transaction to set up the SpdySession |
| 16470 | HttpRequestInfo request1; |
| 16471 | request1.method = "GET"; |
| 16472 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16473 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16474 | request1.traffic_annotation = |
| 16475 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16476 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16477 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16478 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16479 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16480 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16481 | data1.RunUntilPaused(); |
| 16482 | base::RunLoop().RunUntilIdle(); |
| 16483 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16484 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16485 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16486 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16487 | LoadTimingInfo load_timing_info1; |
| 16488 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16489 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16490 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16491 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16492 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16493 | HttpRequestInfo request2; |
| 16494 | request2.method = "GET"; |
| 16495 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16496 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16497 | request2.traffic_annotation = |
| 16498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16499 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16500 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16501 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16502 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16503 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16504 | data1.RunUntilPaused(); |
| 16505 | base::RunLoop().RunUntilIdle(); |
| 16506 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16507 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16508 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16509 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16510 | |
| 16511 | LoadTimingInfo load_timing_info2; |
| 16512 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16513 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16514 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16515 | // HTTP requests over a SPDY session should have a different connection |
| 16516 | // socket_log_id than requests over a tunnel. |
| 16517 | 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] | 16518 | } |
| 16519 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16520 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16521 | // that we do not pool other origins that resolve to the same IP when |
| 16522 | // the certificate does not match the new origin. |
| 16523 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16524 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16525 | const std::string url1 = "http://www.example.org/"; |
| 16526 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16527 | const std::string ip_addr = "1.2.3.4"; |
| 16528 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16529 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16530 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16531 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16532 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16533 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16534 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16535 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16536 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16537 | |
| 16538 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16539 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16540 | }; |
| 16541 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16542 | spdy::SpdySerializedFrame resp1( |
| 16543 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16544 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16545 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16546 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16547 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16548 | }; |
| 16549 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16550 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16551 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16552 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16553 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16554 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16555 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16556 | |
| 16557 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16558 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16559 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16560 | |
| 16561 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16562 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16563 | }; |
| 16564 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16565 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16566 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16567 | spdy::SpdySerializedFrame body2( |
| 16568 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16569 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16570 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16571 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16572 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16573 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16574 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16575 | |
| 16576 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16577 | // all others direct. |
| 16578 | ProxyConfig proxy_config; |
| 16579 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16580 | session_deps_.proxy_resolution_service = |
| 16581 | std::make_unique<ProxyResolutionService>( |
| 16582 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16583 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16584 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16585 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16586 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16587 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16588 | // Load a valid cert. Note, that this does not need to |
| 16589 | // be valid for proxy because the MockSSLClientSocket does |
| 16590 | // not actually verify it. But SpdySession will use this |
| 16591 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16592 | ssl1.ssl_info.cert = |
| 16593 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16594 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16596 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16597 | |
| 16598 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16599 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16601 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16602 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16603 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16604 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16605 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16607 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16608 | |
| 16609 | // Start the first transaction to set up the SpdySession |
| 16610 | HttpRequestInfo request1; |
| 16611 | request1.method = "GET"; |
| 16612 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16613 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16614 | request1.traffic_annotation = |
| 16615 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16616 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16617 | TestCompletionCallback callback1; |
| 16618 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16619 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16620 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16621 | data1.RunUntilPaused(); |
| 16622 | base::RunLoop().RunUntilIdle(); |
| 16623 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16624 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16625 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16626 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16627 | |
| 16628 | // Now, start the HTTP request |
| 16629 | HttpRequestInfo request2; |
| 16630 | request2.method = "GET"; |
| 16631 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16632 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16633 | request2.traffic_annotation = |
| 16634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16635 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16636 | TestCompletionCallback callback2; |
| 16637 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16638 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16639 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16640 | |
| 16641 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16642 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16643 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16644 | } |
| 16645 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16646 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16647 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16648 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16649 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16650 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16651 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16652 | |
| 16653 | MockRead reads1[] = { |
| 16654 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16655 | }; |
| 16656 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16657 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16658 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16659 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16660 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16661 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16662 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16663 | }; |
| 16664 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16665 | spdy::SpdySerializedFrame resp2( |
| 16666 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16667 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16668 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16669 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16670 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16671 | }; |
| 16672 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16673 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16674 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16675 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16676 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16677 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16678 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16679 | |
| 16680 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16681 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16682 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16683 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16685 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16686 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16687 | |
| 16688 | // Start the first transaction to set up the SpdySession and verify that |
| 16689 | // connection was closed. |
| 16690 | HttpRequestInfo request1; |
| 16691 | request1.method = "GET"; |
| 16692 | request1.url = GURL(https_url); |
| 16693 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16694 | request1.traffic_annotation = |
| 16695 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16696 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16697 | TestCompletionCallback callback1; |
| 16698 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16699 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16700 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16701 | |
| 16702 | // Now, start the second request and make sure it succeeds. |
| 16703 | HttpRequestInfo request2; |
| 16704 | request2.method = "GET"; |
| 16705 | request2.url = GURL(https_url); |
| 16706 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16707 | request2.traffic_annotation = |
| 16708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16709 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16710 | TestCompletionCallback callback2; |
| 16711 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16712 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16713 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16714 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16715 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16716 | } |
| 16717 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16718 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16719 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16720 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16721 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16722 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16723 | |
| 16724 | // Use two different hosts with different IPs so they don't get pooled. |
| 16725 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16726 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16728 | |
| 16729 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16730 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16731 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16732 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16734 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16735 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16736 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16737 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16738 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16739 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16740 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16741 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16742 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16743 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16744 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16745 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16746 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16747 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16748 | }; |
| 16749 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16750 | // Use a separate test instance for the separate SpdySession that will be |
| 16751 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16752 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16753 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16754 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16755 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16756 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16757 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16758 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16759 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16760 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16761 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16762 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16763 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16764 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16765 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16766 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16767 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16768 | }; |
| 16769 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16770 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16771 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16772 | |
| 16773 | MockWrite http_write[] = { |
| 16774 | MockWrite("GET / HTTP/1.1\r\n" |
| 16775 | "Host: www.a.com\r\n" |
| 16776 | "Connection: keep-alive\r\n\r\n"), |
| 16777 | }; |
| 16778 | |
| 16779 | MockRead http_read[] = { |
| 16780 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16781 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16782 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16783 | MockRead("hello!"), |
| 16784 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16785 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16786 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16787 | |
| 16788 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16789 | SpdySessionKey spdy_session_key_a( |
| 16790 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16791 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16792 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16793 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16794 | |
| 16795 | TestCompletionCallback callback; |
| 16796 | HttpRequestInfo request1; |
| 16797 | request1.method = "GET"; |
| 16798 | request1.url = GURL("https://www.a.com/"); |
| 16799 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16800 | request1.traffic_annotation = |
| 16801 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16802 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16803 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16805 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16807 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16808 | |
| 16809 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16810 | ASSERT_TRUE(response); |
| 16811 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16812 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16813 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16814 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16815 | |
| 16816 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16817 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16818 | EXPECT_EQ("hello!", response_data); |
| 16819 | trans.reset(); |
| 16820 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16821 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16822 | |
| 16823 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16824 | SpdySessionKey spdy_session_key_b( |
| 16825 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16826 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16827 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16828 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16829 | HttpRequestInfo request2; |
| 16830 | request2.method = "GET"; |
| 16831 | request2.url = GURL("https://www.b.com/"); |
| 16832 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16833 | request2.traffic_annotation = |
| 16834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16835 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16836 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16838 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16840 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16841 | |
| 16842 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16843 | ASSERT_TRUE(response); |
| 16844 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16845 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16846 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16847 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16848 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16849 | EXPECT_EQ("hello!", response_data); |
| 16850 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16851 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16852 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16853 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16854 | |
| 16855 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16856 | SpdySessionKey spdy_session_key_a1( |
| 16857 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16858 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16859 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16860 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16861 | HttpRequestInfo request3; |
| 16862 | request3.method = "GET"; |
| 16863 | request3.url = GURL("http://www.a.com/"); |
| 16864 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16865 | request3.traffic_annotation = |
| 16866 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16867 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16868 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16869 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16870 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16871 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16872 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16873 | |
| 16874 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16875 | ASSERT_TRUE(response); |
| 16876 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16877 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16878 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16879 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16880 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16881 | EXPECT_EQ("hello!", response_data); |
| 16882 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16883 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16884 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16885 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16886 | } |
| 16887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16888 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16889 | HttpRequestInfo request; |
| 16890 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16891 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16892 | request.traffic_annotation = |
| 16893 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16894 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16897 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16898 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16899 | StaticSocketDataProvider data; |
| 16900 | data.set_connect_data(mock_connect); |
| 16901 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16902 | |
| 16903 | TestCompletionCallback callback; |
| 16904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16905 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16907 | |
| 16908 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16909 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16910 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16911 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16912 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16913 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16914 | |
| 16915 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16916 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16917 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16918 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16919 | |
| 16920 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16921 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16922 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16923 | } |
| 16924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16925 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | HttpRequestInfo request; |
| 16927 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16928 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16929 | request.traffic_annotation = |
| 16930 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16931 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16934 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16935 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16936 | StaticSocketDataProvider data; |
| 16937 | data.set_connect_data(mock_connect); |
| 16938 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16939 | |
| 16940 | TestCompletionCallback callback; |
| 16941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16944 | |
| 16945 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16946 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16947 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16948 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16949 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16950 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16951 | |
| 16952 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16953 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16954 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16955 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16956 | |
| 16957 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16958 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16959 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16960 | } |
| 16961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16962 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16963 | HttpRequestInfo request; |
| 16964 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16965 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16966 | request.traffic_annotation = |
| 16967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16968 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16969 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16970 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16971 | |
| 16972 | MockWrite data_writes[] = { |
| 16973 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16974 | }; |
| 16975 | MockRead data_reads[] = { |
| 16976 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16977 | }; |
| 16978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16979 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16980 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16981 | |
| 16982 | TestCompletionCallback callback; |
| 16983 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16984 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16986 | |
| 16987 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16988 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16989 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16990 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16991 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16992 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16993 | } |
| 16994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16995 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16996 | HttpRequestInfo request; |
| 16997 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16998 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16999 | request.traffic_annotation = |
| 17000 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17001 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17003 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17004 | |
| 17005 | MockWrite data_writes[] = { |
| 17006 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 17007 | }; |
| 17008 | MockRead data_reads[] = { |
| 17009 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 17010 | }; |
| 17011 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17012 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17014 | |
| 17015 | TestCompletionCallback callback; |
| 17016 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17017 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17019 | |
| 17020 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17021 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17022 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17023 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17024 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17025 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17026 | } |
| 17027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17028 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17029 | HttpRequestInfo request; |
| 17030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17031 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17032 | request.traffic_annotation = |
| 17033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17037 | |
| 17038 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17039 | MockWrite( |
| 17040 | "GET / HTTP/1.1\r\n" |
| 17041 | "Host: www.example.org\r\n" |
| 17042 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17043 | }; |
| 17044 | MockRead data_reads[] = { |
| 17045 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17046 | }; |
| 17047 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17048 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17049 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17050 | |
| 17051 | TestCompletionCallback callback; |
| 17052 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17055 | |
| 17056 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17057 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17058 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17059 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17060 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17061 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17062 | } |
| 17063 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17064 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17065 | HttpRequestInfo request; |
| 17066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17067 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17068 | request.traffic_annotation = |
| 17069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17070 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17072 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17073 | |
| 17074 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17075 | MockWrite( |
| 17076 | "GET / HTTP/1.1\r\n" |
| 17077 | "Host: www.example.org\r\n" |
| 17078 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17079 | }; |
| 17080 | MockRead data_reads[] = { |
| 17081 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17082 | }; |
| 17083 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17084 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17086 | |
| 17087 | TestCompletionCallback callback; |
| 17088 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17089 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17091 | |
| 17092 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17093 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17094 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17095 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17096 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17097 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17098 | } |
| 17099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17100 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17101 | HttpRequestInfo request; |
| 17102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17103 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17104 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17105 | request.traffic_annotation = |
| 17106 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17107 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17108 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17109 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17110 | |
| 17111 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17112 | MockWrite( |
| 17113 | "GET / HTTP/1.1\r\n" |
| 17114 | "Host: www.example.org\r\n" |
| 17115 | "Connection: keep-alive\r\n" |
| 17116 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17117 | }; |
| 17118 | MockRead data_reads[] = { |
| 17119 | MockRead("HTTP/1.1 200 OK\r\n" |
| 17120 | "Content-Length: 5\r\n\r\n" |
| 17121 | "hello"), |
| 17122 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 17123 | }; |
| 17124 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17125 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17127 | |
| 17128 | TestCompletionCallback callback; |
| 17129 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17130 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17132 | |
| 17133 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17135 | |
| 17136 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17137 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17138 | std::string foo; |
| 17139 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17140 | EXPECT_EQ("bar", foo); |
| 17141 | } |
| 17142 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17143 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17144 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17145 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17146 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17147 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17148 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17149 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17150 | |
| 17151 | // Set up SSL request. |
| 17152 | |
| 17153 | HttpRequestInfo ssl_request; |
| 17154 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17155 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17156 | ssl_request.traffic_annotation = |
| 17157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17158 | |
| 17159 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17160 | MockWrite( |
| 17161 | "GET / HTTP/1.1\r\n" |
| 17162 | "Host: www.example.org\r\n" |
| 17163 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17164 | }; |
| 17165 | MockRead ssl_reads[] = { |
| 17166 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17167 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17168 | MockRead("hello world"), |
| 17169 | MockRead(SYNCHRONOUS, OK), |
| 17170 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17171 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17172 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17173 | |
| 17174 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17176 | |
| 17177 | // Set up HTTP request. |
| 17178 | |
| 17179 | HttpRequestInfo http_request; |
| 17180 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17181 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17182 | http_request.traffic_annotation = |
| 17183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17184 | |
| 17185 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17186 | MockWrite( |
| 17187 | "GET / HTTP/1.1\r\n" |
| 17188 | "Host: www.example.org\r\n" |
| 17189 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17190 | }; |
| 17191 | MockRead http_reads[] = { |
| 17192 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17193 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17194 | MockRead("falafel"), |
| 17195 | MockRead(SYNCHRONOUS, OK), |
| 17196 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17197 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17198 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17199 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17201 | |
| 17202 | // Start the SSL request. |
| 17203 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17204 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17205 | ASSERT_EQ(ERR_IO_PENDING, |
| 17206 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17207 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17208 | |
| 17209 | // Start the HTTP request. Pool should stall. |
| 17210 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17211 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17212 | ASSERT_EQ(ERR_IO_PENDING, |
| 17213 | http_trans.Start(&http_request, http_callback.callback(), |
| 17214 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17215 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17216 | |
| 17217 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17218 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17219 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17220 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17221 | EXPECT_EQ("hello world", response_data); |
| 17222 | |
| 17223 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17224 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17225 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17226 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17227 | |
| 17228 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17229 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17230 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17231 | EXPECT_EQ("falafel", response_data); |
| 17232 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17233 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17234 | } |
| 17235 | |
| 17236 | // Tests that when a SSL connection is established but there's no corresponding |
| 17237 | // request that needs it, the new socket is closed if the transport socket pool |
| 17238 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17239 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17240 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17241 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17242 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17243 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17244 | |
| 17245 | // Set up an ssl request. |
| 17246 | |
| 17247 | HttpRequestInfo ssl_request; |
| 17248 | ssl_request.method = "GET"; |
| 17249 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17250 | ssl_request.traffic_annotation = |
| 17251 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17252 | |
| 17253 | // No data will be sent on the SSL socket. |
| 17254 | StaticSocketDataProvider ssl_data; |
| 17255 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17256 | |
| 17257 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17259 | |
| 17260 | // Set up HTTP request. |
| 17261 | |
| 17262 | HttpRequestInfo http_request; |
| 17263 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17264 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17265 | http_request.traffic_annotation = |
| 17266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17267 | |
| 17268 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17269 | MockWrite( |
| 17270 | "GET / HTTP/1.1\r\n" |
| 17271 | "Host: www.example.org\r\n" |
| 17272 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17273 | }; |
| 17274 | MockRead http_reads[] = { |
| 17275 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17276 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17277 | MockRead("falafel"), |
| 17278 | MockRead(SYNCHRONOUS, OK), |
| 17279 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17280 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17281 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17282 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17284 | |
| 17285 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17286 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17287 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17288 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17289 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17290 | |
| 17291 | // Start the HTTP request. Pool should stall. |
| 17292 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17293 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17294 | ASSERT_EQ(ERR_IO_PENDING, |
| 17295 | http_trans.Start(&http_request, http_callback.callback(), |
| 17296 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17297 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17298 | |
| 17299 | // The SSL connection will automatically be closed once the connection is |
| 17300 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17301 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17302 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17303 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17304 | EXPECT_EQ("falafel", response_data); |
| 17305 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17306 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17307 | } |
| 17308 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17309 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17310 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17311 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17312 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17313 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17314 | |
| 17315 | HttpRequestInfo request; |
| 17316 | request.method = "POST"; |
| 17317 | request.url = GURL("http://www.foo.com/"); |
| 17318 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17319 | request.traffic_annotation = |
| 17320 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17321 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17322 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17323 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17324 | // Send headers successfully, but get an error while sending the body. |
| 17325 | MockWrite data_writes[] = { |
| 17326 | MockWrite("POST / HTTP/1.1\r\n" |
| 17327 | "Host: www.foo.com\r\n" |
| 17328 | "Connection: keep-alive\r\n" |
| 17329 | "Content-Length: 3\r\n\r\n"), |
| 17330 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17331 | }; |
| 17332 | |
| 17333 | MockRead data_reads[] = { |
| 17334 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17335 | MockRead("hello world"), |
| 17336 | MockRead(SYNCHRONOUS, OK), |
| 17337 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17338 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17339 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17340 | |
| 17341 | TestCompletionCallback callback; |
| 17342 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17343 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17344 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17345 | |
| 17346 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17347 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17348 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17349 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17350 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17351 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17352 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17353 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17354 | |
| 17355 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17356 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17357 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17358 | EXPECT_EQ("hello world", response_data); |
| 17359 | } |
| 17360 | |
| 17361 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17362 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17363 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17364 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17365 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17366 | MockWrite data_writes[] = { |
| 17367 | MockWrite("GET / HTTP/1.1\r\n" |
| 17368 | "Host: www.foo.com\r\n" |
| 17369 | "Connection: keep-alive\r\n\r\n"), |
| 17370 | MockWrite("POST / HTTP/1.1\r\n" |
| 17371 | "Host: www.foo.com\r\n" |
| 17372 | "Connection: keep-alive\r\n" |
| 17373 | "Content-Length: 3\r\n\r\n"), |
| 17374 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17375 | }; |
| 17376 | |
| 17377 | MockRead data_reads[] = { |
| 17378 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17379 | "Content-Length: 14\r\n\r\n"), |
| 17380 | MockRead("first response"), |
| 17381 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17382 | "Content-Length: 15\r\n\r\n"), |
| 17383 | MockRead("second response"), |
| 17384 | MockRead(SYNCHRONOUS, OK), |
| 17385 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17386 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17388 | |
| 17389 | TestCompletionCallback callback; |
| 17390 | HttpRequestInfo request1; |
| 17391 | request1.method = "GET"; |
| 17392 | request1.url = GURL("http://www.foo.com/"); |
| 17393 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17394 | request1.traffic_annotation = |
| 17395 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17396 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17397 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17398 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17399 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17401 | |
| 17402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17404 | |
| 17405 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17406 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17407 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17408 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17409 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17410 | |
| 17411 | std::string response_data1; |
| 17412 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17414 | EXPECT_EQ("first response", response_data1); |
| 17415 | // Delete the transaction to release the socket back into the socket pool. |
| 17416 | trans1.reset(); |
| 17417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17418 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17419 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17420 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17421 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17422 | |
| 17423 | HttpRequestInfo request2; |
| 17424 | request2.method = "POST"; |
| 17425 | request2.url = GURL("http://www.foo.com/"); |
| 17426 | request2.upload_data_stream = &upload_data_stream; |
| 17427 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17428 | request2.traffic_annotation = |
| 17429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17431 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17432 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17434 | |
| 17435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17436 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17438 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17439 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17440 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17441 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17442 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17443 | |
| 17444 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17445 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17447 | EXPECT_EQ("second response", response_data2); |
| 17448 | } |
| 17449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17450 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17451 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17452 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17453 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17454 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17455 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17456 | |
| 17457 | HttpRequestInfo request; |
| 17458 | request.method = "POST"; |
| 17459 | request.url = GURL("http://www.foo.com/"); |
| 17460 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17461 | request.traffic_annotation = |
| 17462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17463 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17466 | // Send headers successfully, but get an error while sending the body. |
| 17467 | MockWrite data_writes[] = { |
| 17468 | MockWrite("POST / HTTP/1.1\r\n" |
| 17469 | "Host: www.foo.com\r\n" |
| 17470 | "Connection: keep-alive\r\n" |
| 17471 | "Content-Length: 3\r\n\r\n" |
| 17472 | "fo"), |
| 17473 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17474 | }; |
| 17475 | |
| 17476 | MockRead data_reads[] = { |
| 17477 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17478 | MockRead("hello world"), |
| 17479 | MockRead(SYNCHRONOUS, OK), |
| 17480 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17481 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17482 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17483 | |
| 17484 | TestCompletionCallback callback; |
| 17485 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17486 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17488 | |
| 17489 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17492 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17493 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17494 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17495 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17496 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17497 | |
| 17498 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17499 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17501 | EXPECT_EQ("hello world", response_data); |
| 17502 | } |
| 17503 | |
| 17504 | // This tests the more common case than the previous test, where headers and |
| 17505 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17506 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17507 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17508 | |
| 17509 | HttpRequestInfo request; |
| 17510 | request.method = "POST"; |
| 17511 | request.url = GURL("http://www.foo.com/"); |
| 17512 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17513 | request.traffic_annotation = |
| 17514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17518 | // Send headers successfully, but get an error while sending the body. |
| 17519 | MockWrite data_writes[] = { |
| 17520 | MockWrite("POST / HTTP/1.1\r\n" |
| 17521 | "Host: www.foo.com\r\n" |
| 17522 | "Connection: keep-alive\r\n" |
| 17523 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17524 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17525 | }; |
| 17526 | |
| 17527 | MockRead data_reads[] = { |
| 17528 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17529 | MockRead("hello world"), |
| 17530 | MockRead(SYNCHRONOUS, OK), |
| 17531 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17532 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17533 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17534 | |
| 17535 | TestCompletionCallback callback; |
| 17536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17537 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17540 | // they can't be merged with the body in a single send. Not currently |
| 17541 | // necessary since a chunked body is never merged with headers, but this makes |
| 17542 | // the test more future proof. |
| 17543 | base::RunLoop().RunUntilIdle(); |
| 17544 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17545 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17546 | |
| 17547 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17548 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17550 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17551 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17552 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17553 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17554 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17555 | |
| 17556 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17557 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17558 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17559 | EXPECT_EQ("hello world", response_data); |
| 17560 | } |
| 17561 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17562 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17563 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17564 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17565 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17566 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17567 | |
| 17568 | HttpRequestInfo request; |
| 17569 | request.method = "POST"; |
| 17570 | request.url = GURL("http://www.foo.com/"); |
| 17571 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17572 | request.traffic_annotation = |
| 17573 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17574 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17576 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17577 | |
| 17578 | MockWrite data_writes[] = { |
| 17579 | MockWrite("POST / HTTP/1.1\r\n" |
| 17580 | "Host: www.foo.com\r\n" |
| 17581 | "Connection: keep-alive\r\n" |
| 17582 | "Content-Length: 3\r\n\r\n"), |
| 17583 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17584 | }; |
| 17585 | |
| 17586 | MockRead data_reads[] = { |
| 17587 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17588 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17589 | MockRead("hello world"), |
| 17590 | MockRead(SYNCHRONOUS, OK), |
| 17591 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17592 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17594 | |
| 17595 | TestCompletionCallback callback; |
| 17596 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17597 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17599 | |
| 17600 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17601 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17604 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17605 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17606 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17607 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17608 | |
| 17609 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17610 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17611 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17612 | EXPECT_EQ("hello world", response_data); |
| 17613 | } |
| 17614 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17615 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17616 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17617 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17618 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17619 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17620 | |
| 17621 | HttpRequestInfo request; |
| 17622 | request.method = "POST"; |
| 17623 | request.url = GURL("http://www.foo.com/"); |
| 17624 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17625 | request.traffic_annotation = |
| 17626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17629 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17630 | // Send headers successfully, but get an error while sending the body. |
| 17631 | MockWrite data_writes[] = { |
| 17632 | MockWrite("POST / HTTP/1.1\r\n" |
| 17633 | "Host: www.foo.com\r\n" |
| 17634 | "Connection: keep-alive\r\n" |
| 17635 | "Content-Length: 3\r\n\r\n"), |
| 17636 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17637 | }; |
| 17638 | |
| 17639 | MockRead data_reads[] = { |
| 17640 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17641 | MockRead("hello world"), |
| 17642 | MockRead(SYNCHRONOUS, OK), |
| 17643 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17644 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17646 | |
| 17647 | TestCompletionCallback callback; |
| 17648 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17649 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17651 | |
| 17652 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17653 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17654 | } |
| 17655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17656 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17657 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17658 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17659 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17660 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17661 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17662 | |
| 17663 | HttpRequestInfo request; |
| 17664 | request.method = "POST"; |
| 17665 | request.url = GURL("http://www.foo.com/"); |
| 17666 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17667 | request.traffic_annotation = |
| 17668 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17669 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17672 | // Send headers successfully, but get an error while sending the body. |
| 17673 | MockWrite data_writes[] = { |
| 17674 | MockWrite("POST / HTTP/1.1\r\n" |
| 17675 | "Host: www.foo.com\r\n" |
| 17676 | "Connection: keep-alive\r\n" |
| 17677 | "Content-Length: 3\r\n\r\n"), |
| 17678 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17679 | }; |
| 17680 | |
| 17681 | MockRead data_reads[] = { |
| 17682 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17683 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17684 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17685 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17686 | MockRead(SYNCHRONOUS, OK), |
| 17687 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17688 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17690 | |
| 17691 | TestCompletionCallback callback; |
| 17692 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17693 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17695 | |
| 17696 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17697 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17698 | } |
| 17699 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17700 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17701 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17702 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17703 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17704 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17705 | |
| 17706 | HttpRequestInfo request; |
| 17707 | request.method = "POST"; |
| 17708 | request.url = GURL("http://www.foo.com/"); |
| 17709 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17710 | request.traffic_annotation = |
| 17711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17712 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17715 | // Send headers successfully, but get an error while sending the body. |
| 17716 | MockWrite data_writes[] = { |
| 17717 | MockWrite("POST / HTTP/1.1\r\n" |
| 17718 | "Host: www.foo.com\r\n" |
| 17719 | "Connection: keep-alive\r\n" |
| 17720 | "Content-Length: 3\r\n\r\n"), |
| 17721 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17722 | }; |
| 17723 | |
| 17724 | MockRead data_reads[] = { |
| 17725 | MockRead("HTTP 0.9 rocks!"), |
| 17726 | MockRead(SYNCHRONOUS, OK), |
| 17727 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17728 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17730 | |
| 17731 | TestCompletionCallback callback; |
| 17732 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17733 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17734 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17735 | |
| 17736 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17737 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17738 | } |
| 17739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17740 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17741 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17742 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17743 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17744 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17745 | |
| 17746 | HttpRequestInfo request; |
| 17747 | request.method = "POST"; |
| 17748 | request.url = GURL("http://www.foo.com/"); |
| 17749 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17750 | request.traffic_annotation = |
| 17751 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17752 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17755 | // Send headers successfully, but get an error while sending the body. |
| 17756 | MockWrite data_writes[] = { |
| 17757 | MockWrite("POST / HTTP/1.1\r\n" |
| 17758 | "Host: www.foo.com\r\n" |
| 17759 | "Connection: keep-alive\r\n" |
| 17760 | "Content-Length: 3\r\n\r\n"), |
| 17761 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17762 | }; |
| 17763 | |
| 17764 | MockRead data_reads[] = { |
| 17765 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17766 | MockRead(SYNCHRONOUS, OK), |
| 17767 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17768 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17769 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17770 | |
| 17771 | TestCompletionCallback callback; |
| 17772 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17773 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17774 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17775 | |
| 17776 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17777 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17778 | } |
| 17779 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17780 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17781 | |
| 17782 | namespace { |
| 17783 | |
| 17784 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17785 | headers->SetHeader("Connection", "Upgrade"); |
| 17786 | headers->SetHeader("Upgrade", "websocket"); |
| 17787 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17788 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17789 | } |
| 17790 | |
| 17791 | } // namespace |
| 17792 | |
| 17793 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17794 | for (bool secure : {true, false}) { |
| 17795 | MockWrite data_writes[] = { |
| 17796 | MockWrite("GET / HTTP/1.1\r\n" |
| 17797 | "Host: www.example.org\r\n" |
| 17798 | "Connection: Upgrade\r\n" |
| 17799 | "Upgrade: websocket\r\n" |
| 17800 | "Origin: http://www.example.org\r\n" |
| 17801 | "Sec-WebSocket-Version: 13\r\n" |
| 17802 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17803 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17804 | "client_max_window_bits\r\n\r\n")}; |
| 17805 | |
| 17806 | MockRead data_reads[] = { |
| 17807 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17808 | "Upgrade: websocket\r\n" |
| 17809 | "Connection: Upgrade\r\n" |
| 17810 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17811 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17812 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17814 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17815 | if (secure) |
| 17816 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17817 | |
| 17818 | HttpRequestInfo request; |
| 17819 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17820 | request.url = |
| 17821 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17822 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17823 | request.traffic_annotation = |
| 17824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17825 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17826 | TestWebSocketHandshakeStreamCreateHelper |
| 17827 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17828 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17830 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17831 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17832 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17833 | |
| 17834 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17835 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17837 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17838 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17839 | ASSERT_TRUE(stream_request); |
| 17840 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17841 | stream_request->websocket_handshake_stream_create_helper()); |
| 17842 | |
| 17843 | rv = callback.WaitForResult(); |
| 17844 | EXPECT_THAT(rv, IsOk()); |
| 17845 | |
| 17846 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17847 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17848 | } |
| 17849 | } |
| 17850 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17851 | // Verify that proxy headers are not sent to the destination server when |
| 17852 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17853 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17854 | HttpRequestInfo request; |
| 17855 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17856 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17857 | request.traffic_annotation = |
| 17858 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17859 | AddWebSocketHeaders(&request.extra_headers); |
| 17860 | |
| 17861 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17862 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17863 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17864 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17865 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17867 | |
| 17868 | // Since a proxy is configured, try to establish a tunnel. |
| 17869 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17870 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17871 | "Host: www.example.org:443\r\n" |
| 17872 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17873 | |
| 17874 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17875 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17876 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17877 | "Host: www.example.org:443\r\n" |
| 17878 | "Proxy-Connection: keep-alive\r\n" |
| 17879 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17880 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17881 | MockWrite("GET / HTTP/1.1\r\n" |
| 17882 | "Host: www.example.org\r\n" |
| 17883 | "Connection: Upgrade\r\n" |
| 17884 | "Upgrade: websocket\r\n" |
| 17885 | "Origin: http://www.example.org\r\n" |
| 17886 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17887 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17888 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17889 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17890 | |
| 17891 | // The proxy responds to the connect with a 407, using a persistent |
| 17892 | // connection. |
| 17893 | MockRead data_reads[] = { |
| 17894 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17895 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17896 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17897 | "Content-Length: 0\r\n" |
| 17898 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17899 | |
| 17900 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17901 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17902 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17903 | "Upgrade: websocket\r\n" |
| 17904 | "Connection: Upgrade\r\n" |
| 17905 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17906 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17907 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17909 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17910 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17911 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17912 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17913 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17914 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17915 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17916 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17917 | &websocket_stream_create_helper); |
| 17918 | |
| 17919 | { |
| 17920 | TestCompletionCallback callback; |
| 17921 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17922 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17924 | |
| 17925 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17926 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17927 | } |
| 17928 | |
| 17929 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17930 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17931 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17932 | EXPECT_EQ(407, response->headers->response_code()); |
| 17933 | |
| 17934 | { |
| 17935 | TestCompletionCallback callback; |
| 17936 | |
| 17937 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17938 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17940 | |
| 17941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17942 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17943 | } |
| 17944 | |
| 17945 | response = trans->GetResponseInfo(); |
| 17946 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17947 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17948 | |
| 17949 | EXPECT_EQ(101, response->headers->response_code()); |
| 17950 | |
| 17951 | trans.reset(); |
| 17952 | session->CloseAllConnections(); |
| 17953 | } |
| 17954 | |
| 17955 | // Verify that proxy headers are not sent to the destination server when |
| 17956 | // establishing a tunnel for an insecure WebSocket connection. |
| 17957 | // This requires the authentication info to be injected into the auth cache |
| 17958 | // due to crbug.com/395064 |
| 17959 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17960 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17961 | HttpRequestInfo request; |
| 17962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17963 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17964 | request.traffic_annotation = |
| 17965 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17966 | AddWebSocketHeaders(&request.extra_headers); |
| 17967 | |
| 17968 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17969 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17970 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17971 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17972 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17974 | |
| 17975 | MockWrite data_writes[] = { |
| 17976 | // Try to establish a tunnel for the WebSocket connection, with |
| 17977 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17978 | // they cannot and will not use the same TCP/IP connection as the |
| 17979 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17980 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17981 | "Host: www.example.org:80\r\n" |
| 17982 | "Proxy-Connection: keep-alive\r\n" |
| 17983 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17984 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17985 | MockWrite("GET / HTTP/1.1\r\n" |
| 17986 | "Host: www.example.org\r\n" |
| 17987 | "Connection: Upgrade\r\n" |
| 17988 | "Upgrade: websocket\r\n" |
| 17989 | "Origin: http://www.example.org\r\n" |
| 17990 | "Sec-WebSocket-Version: 13\r\n" |
| 17991 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17992 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17993 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17994 | |
| 17995 | MockRead data_reads[] = { |
| 17996 | // HTTP CONNECT with credentials. |
| 17997 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17998 | |
| 17999 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18000 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18001 | "Upgrade: websocket\r\n" |
| 18002 | "Connection: Upgrade\r\n" |
| 18003 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18004 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18005 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18006 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18007 | |
| 18008 | session->http_auth_cache()->Add( |
| 18009 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 18010 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 18011 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18012 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 18013 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18014 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18015 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18016 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 18017 | &websocket_stream_create_helper); |
| 18018 | |
| 18019 | TestCompletionCallback callback; |
| 18020 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18021 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18023 | |
| 18024 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18025 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18026 | |
| 18027 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18028 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18029 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18030 | |
| 18031 | EXPECT_EQ(101, response->headers->response_code()); |
| 18032 | |
| 18033 | trans.reset(); |
| 18034 | session->CloseAllConnections(); |
| 18035 | } |
| 18036 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 18037 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 18038 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 18039 | for (bool secure : {true, false}) { |
| 18040 | SCOPED_TRACE(secure); |
| 18041 | session_deps_.proxy_resolution_service = |
| 18042 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18043 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18044 | session_deps_.enable_quic = true; |
| 18045 | |
| 18046 | HttpRequestInfo request; |
| 18047 | request.url = |
| 18048 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 18049 | AddWebSocketHeaders(&request.extra_headers); |
| 18050 | request.traffic_annotation = |
| 18051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18052 | |
| 18053 | TestWebSocketHandshakeStreamCreateHelper |
| 18054 | websocket_handshake_stream_create_helper; |
| 18055 | |
| 18056 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18057 | HttpNetworkTransaction trans(LOW, session.get()); |
| 18058 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 18059 | &websocket_handshake_stream_create_helper); |
| 18060 | |
| 18061 | TestCompletionCallback callback; |
| 18062 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18064 | |
| 18065 | rv = callback.WaitForResult(); |
| 18066 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18067 | } |
| 18068 | } |
| 18069 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18070 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18071 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18072 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18073 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18074 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18075 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18076 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18077 | |
| 18078 | HttpRequestInfo request; |
| 18079 | request.method = "POST"; |
| 18080 | request.url = GURL("http://www.foo.com/"); |
| 18081 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18082 | request.traffic_annotation = |
| 18083 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18084 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18086 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18087 | MockWrite data_writes[] = { |
| 18088 | MockWrite("POST / HTTP/1.1\r\n" |
| 18089 | "Host: www.foo.com\r\n" |
| 18090 | "Connection: keep-alive\r\n" |
| 18091 | "Content-Length: 3\r\n\r\n"), |
| 18092 | MockWrite("foo"), |
| 18093 | }; |
| 18094 | |
| 18095 | MockRead data_reads[] = { |
| 18096 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18097 | MockRead(SYNCHRONOUS, OK), |
| 18098 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18099 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18101 | |
| 18102 | TestCompletionCallback callback; |
| 18103 | |
| 18104 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18105 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18106 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18107 | |
| 18108 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18109 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18110 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18111 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18112 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18113 | } |
| 18114 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18115 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18116 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18117 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18118 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18119 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18120 | |
| 18121 | HttpRequestInfo request; |
| 18122 | request.method = "POST"; |
| 18123 | request.url = GURL("http://www.foo.com/"); |
| 18124 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18125 | request.traffic_annotation = |
| 18126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18129 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18130 | MockWrite data_writes[] = { |
| 18131 | MockWrite("POST / HTTP/1.1\r\n" |
| 18132 | "Host: www.foo.com\r\n" |
| 18133 | "Connection: keep-alive\r\n" |
| 18134 | "Content-Length: 3\r\n\r\n"), |
| 18135 | MockWrite("foo"), |
| 18136 | }; |
| 18137 | |
| 18138 | MockRead data_reads[] = { |
| 18139 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18140 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18141 | MockRead(SYNCHRONOUS, OK), |
| 18142 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18143 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18144 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18145 | |
| 18146 | TestCompletionCallback callback; |
| 18147 | |
| 18148 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18149 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18150 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18151 | |
| 18152 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18153 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18154 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18155 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18156 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18157 | } |
| 18158 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18159 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18160 | ChunkedUploadDataStream upload_data_stream(0); |
| 18161 | |
| 18162 | HttpRequestInfo request; |
| 18163 | request.method = "POST"; |
| 18164 | request.url = GURL("http://www.foo.com/"); |
| 18165 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18166 | request.traffic_annotation = |
| 18167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18168 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18169 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18170 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18171 | // Send headers successfully, but get an error while sending the body. |
| 18172 | MockWrite data_writes[] = { |
| 18173 | MockWrite("POST / HTTP/1.1\r\n" |
| 18174 | "Host: www.foo.com\r\n" |
| 18175 | "Connection: keep-alive\r\n" |
| 18176 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18177 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18178 | }; |
| 18179 | |
| 18180 | MockRead data_reads[] = { |
| 18181 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18182 | MockRead(SYNCHRONOUS, OK), |
| 18183 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18184 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18185 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18186 | |
| 18187 | TestCompletionCallback callback; |
| 18188 | |
| 18189 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18190 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18191 | |
| 18192 | base::RunLoop().RunUntilIdle(); |
| 18193 | upload_data_stream.AppendData("f", 1, false); |
| 18194 | |
| 18195 | base::RunLoop().RunUntilIdle(); |
| 18196 | upload_data_stream.AppendData("oo", 2, true); |
| 18197 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18198 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18199 | |
| 18200 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18201 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18202 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18203 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18204 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18205 | } |
| 18206 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18207 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18208 | const std::string& accept_encoding, |
| 18209 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18210 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18211 | bool should_match) { |
| 18212 | HttpRequestInfo request; |
| 18213 | request.method = "GET"; |
| 18214 | request.url = GURL("http://www.foo.com/"); |
| 18215 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18216 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18217 | request.traffic_annotation = |
| 18218 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18219 | |
| 18220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18221 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18222 | // Send headers successfully, but get an error while sending the body. |
| 18223 | MockWrite data_writes[] = { |
| 18224 | MockWrite("GET / HTTP/1.1\r\n" |
| 18225 | "Host: www.foo.com\r\n" |
| 18226 | "Connection: keep-alive\r\n" |
| 18227 | "Accept-Encoding: "), |
| 18228 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18229 | }; |
| 18230 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18231 | std::string response_code = "200 OK"; |
| 18232 | std::string extra; |
| 18233 | if (!location.empty()) { |
| 18234 | response_code = "301 Redirect\r\nLocation: "; |
| 18235 | response_code.append(location); |
| 18236 | } |
| 18237 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18238 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18239 | MockRead("HTTP/1.0 "), |
| 18240 | MockRead(response_code.data()), |
| 18241 | MockRead("\r\nContent-Encoding: "), |
| 18242 | MockRead(content_encoding.data()), |
| 18243 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18244 | MockRead(SYNCHRONOUS, OK), |
| 18245 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18246 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18247 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18248 | |
| 18249 | TestCompletionCallback callback; |
| 18250 | |
| 18251 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18253 | |
| 18254 | rv = callback.WaitForResult(); |
| 18255 | if (should_match) { |
| 18256 | EXPECT_THAT(rv, IsOk()); |
| 18257 | } else { |
| 18258 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18259 | } |
| 18260 | } |
| 18261 | |
| 18262 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18263 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18264 | } |
| 18265 | |
| 18266 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18267 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18268 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18269 | } |
| 18270 | |
| 18271 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18272 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18273 | "", false); |
| 18274 | } |
| 18275 | |
| 18276 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18277 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18278 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18279 | } |
| 18280 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18281 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18282 | ProxyConfig proxy_config; |
| 18283 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18284 | proxy_config.set_pac_mandatory(true); |
| 18285 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18286 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18287 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18288 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18289 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18290 | |
| 18291 | HttpRequestInfo request; |
| 18292 | request.method = "GET"; |
| 18293 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18294 | request.traffic_annotation = |
| 18295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18296 | |
| 18297 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18299 | |
| 18300 | TestCompletionCallback callback; |
| 18301 | |
| 18302 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18303 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18304 | EXPECT_THAT(callback.WaitForResult(), |
| 18305 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18306 | } |
| 18307 | |
| 18308 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18309 | ProxyConfig proxy_config; |
| 18310 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18311 | proxy_config.set_pac_mandatory(true); |
| 18312 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18313 | new MockAsyncProxyResolverFactory(false); |
| 18314 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18315 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18316 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18317 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18318 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18319 | HttpRequestInfo request; |
| 18320 | request.method = "GET"; |
| 18321 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18322 | request.traffic_annotation = |
| 18323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18324 | |
| 18325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18327 | |
| 18328 | TestCompletionCallback callback; |
| 18329 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18331 | |
| 18332 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18333 | ERR_FAILED, &resolver); |
| 18334 | EXPECT_THAT(callback.WaitForResult(), |
| 18335 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18336 | } |
| 18337 | |
| 18338 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18339 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18340 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18341 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18342 | session_deps_.enable_quic = false; |
| 18343 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18344 | |
| 18345 | HttpRequestInfo request; |
| 18346 | request.method = "GET"; |
| 18347 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18348 | request.traffic_annotation = |
| 18349 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18350 | |
| 18351 | TestCompletionCallback callback; |
| 18352 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18353 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18355 | |
| 18356 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18357 | } |
| 18358 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18359 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18360 | // Reporting tests |
| 18361 | |
| 18362 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18363 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18364 | protected: |
| 18365 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18366 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18367 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18368 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18369 | test_reporting_context_ = test_reporting_context.get(); |
| 18370 | session_deps_.reporting_service = |
| 18371 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18372 | } |
| 18373 | |
| 18374 | TestReportingContext* reporting_context() const { |
| 18375 | return test_reporting_context_; |
| 18376 | } |
| 18377 | |
| 18378 | void clear_reporting_service() { |
| 18379 | session_deps_.reporting_service.reset(); |
| 18380 | test_reporting_context_ = nullptr; |
| 18381 | } |
| 18382 | |
| 18383 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18384 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18385 | HttpRequestInfo request; |
| 18386 | request.method = "GET"; |
| 18387 | request.url = GURL(url_); |
| 18388 | request.traffic_annotation = |
| 18389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18390 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18391 | MockWrite data_writes[] = { |
| 18392 | MockWrite("GET / HTTP/1.1\r\n" |
| 18393 | "Host: www.example.org\r\n" |
| 18394 | "Connection: keep-alive\r\n\r\n"), |
| 18395 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18396 | MockRead data_reads[] = { |
| 18397 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18398 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18399 | "\"endpoints\": [{\"url\": " |
| 18400 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18401 | MockRead("\r\n"), |
| 18402 | MockRead("hello world"), |
| 18403 | MockRead(SYNCHRONOUS, OK), |
| 18404 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18405 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18406 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18407 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18408 | |
| 18409 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18410 | if (request.url.SchemeIsCryptographic()) { |
| 18411 | ssl.ssl_info.cert = |
| 18412 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18413 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18414 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18416 | } |
| 18417 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18418 | TestCompletionCallback callback; |
| 18419 | auto session = CreateSession(&session_deps_); |
| 18420 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18421 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18422 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18423 | } |
| 18424 | |
| 18425 | protected: |
| 18426 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18427 | |
| 18428 | private: |
| 18429 | TestReportingContext* test_reporting_context_; |
| 18430 | }; |
| 18431 | |
| 18432 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18433 | DontProcessReportToHeaderNoService) { |
| 18434 | base::HistogramTester histograms; |
| 18435 | clear_reporting_service(); |
| 18436 | RequestPolicy(); |
| 18437 | histograms.ExpectBucketCount( |
| 18438 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18439 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18440 | } |
| 18441 | |
| 18442 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18443 | base::HistogramTester histograms; |
| 18444 | url_ = "http://www.example.org/"; |
| 18445 | RequestPolicy(); |
| 18446 | histograms.ExpectBucketCount( |
| 18447 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18448 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18449 | } |
| 18450 | |
| 18451 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18452 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18453 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
| 18454 | const ReportingClient endpoint = |
| 18455 | reporting_context()->cache()->GetEndpointForTesting( |
| 18456 | url::Origin::Create(GURL("https://www.example.org/")), "nel", |
| 18457 | GURL("https://www.example.org/upload/")); |
| 18458 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18459 | } |
| 18460 | |
| 18461 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18462 | DontProcessReportToHeaderInvalidHttps) { |
| 18463 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18464 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18465 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18466 | histograms.ExpectBucketCount( |
| 18467 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18468 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18469 | } |
| 18470 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18471 | |
| 18472 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18473 | // Network Error Logging tests |
| 18474 | |
| 18475 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18476 | namespace { |
| 18477 | |
| 18478 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18479 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18480 | |
| 18481 | } // namespace |
| 18482 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18483 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18484 | : public HttpNetworkTransactionTest { |
| 18485 | protected: |
| 18486 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18487 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18488 | auto network_error_logging_service = |
| 18489 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18490 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18491 | session_deps_.network_error_logging_service = |
| 18492 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18493 | |
| 18494 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18495 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18496 | |
| 18497 | request_.method = "GET"; |
| 18498 | request_.url = GURL(url_); |
| 18499 | request_.extra_headers = extra_headers_; |
| 18500 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18501 | request_.traffic_annotation = |
| 18502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18503 | } |
| 18504 | |
| 18505 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18506 | return test_network_error_logging_service_; |
| 18507 | } |
| 18508 | |
| 18509 | void clear_network_error_logging_service() { |
| 18510 | session_deps_.network_error_logging_service.reset(); |
| 18511 | test_network_error_logging_service_ = nullptr; |
| 18512 | } |
| 18513 | |
| 18514 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18515 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18516 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18517 | MockWrite data_writes[] = { |
| 18518 | MockWrite("GET / HTTP/1.1\r\n" |
| 18519 | "Host: www.example.org\r\n" |
| 18520 | "Connection: keep-alive\r\n"), |
| 18521 | MockWrite(ASYNC, extra_header_string.data(), |
| 18522 | extra_header_string.size()), |
| 18523 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18524 | MockRead data_reads[] = { |
| 18525 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18526 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18527 | MockRead("\r\n"), |
| 18528 | MockRead("hello world"), |
| 18529 | MockRead(SYNCHRONOUS, OK), |
| 18530 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18531 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18532 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18533 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18534 | |
| 18535 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18536 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18537 | ssl.ssl_info.cert = |
| 18538 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18539 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18540 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18542 | } |
| 18543 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18544 | TestCompletionCallback callback; |
| 18545 | auto session = CreateSession(&session_deps_); |
| 18546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18547 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18548 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18549 | |
| 18550 | std::string response_data; |
| 18551 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18552 | EXPECT_EQ("hello world", response_data); |
| 18553 | } |
| 18554 | |
| 18555 | void CheckReport(size_t index, |
| 18556 | int status_code, |
| 18557 | int error_type, |
| 18558 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18559 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18560 | |
| 18561 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18562 | network_error_logging_service()->errors()[index]; |
| 18563 | EXPECT_EQ(url_, error.uri); |
| 18564 | EXPECT_EQ(kReferrer, error.referrer); |
| 18565 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18566 | EXPECT_EQ(server_ip, error.server_ip); |
| 18567 | EXPECT_EQ("http/1.1", error.protocol); |
| 18568 | EXPECT_EQ("GET", error.method); |
| 18569 | EXPECT_EQ(status_code, error.status_code); |
| 18570 | EXPECT_EQ(error_type, error.type); |
| 18571 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18572 | } |
| 18573 | |
| 18574 | protected: |
| 18575 | std::string url_ = "https://www.example.org/"; |
| 18576 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18577 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18578 | HttpRequestHeaders extra_headers_; |
| 18579 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18580 | |
| 18581 | private: |
| 18582 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18583 | }; |
| 18584 | |
| 18585 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18586 | DontProcessNelHeaderNoService) { |
| 18587 | base::HistogramTester histograms; |
| 18588 | clear_network_error_logging_service(); |
| 18589 | RequestPolicy(); |
| 18590 | histograms.ExpectBucketCount( |
| 18591 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18592 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18593 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18594 | 1); |
| 18595 | } |
| 18596 | |
| 18597 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18598 | DontProcessNelHeaderHttp) { |
| 18599 | base::HistogramTester histograms; |
| 18600 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18601 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18602 | RequestPolicy(); |
| 18603 | histograms.ExpectBucketCount( |
| 18604 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18605 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18606 | } |
| 18607 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18608 | // Don't set NEL policies received on a proxied connection. |
| 18609 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18610 | DontProcessNelHeaderProxy) { |
| 18611 | session_deps_.proxy_resolution_service = |
| 18612 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18613 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18614 | BoundTestNetLog log; |
| 18615 | session_deps_.net_log = log.bound().net_log(); |
| 18616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18617 | |
| 18618 | HttpRequestInfo request; |
| 18619 | request.method = "GET"; |
| 18620 | request.url = GURL("https://www.example.org/"); |
| 18621 | request.traffic_annotation = |
| 18622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18623 | |
| 18624 | // Since we have proxy, should try to establish tunnel. |
| 18625 | MockWrite data_writes1[] = { |
| 18626 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18627 | "Host: www.example.org:443\r\n" |
| 18628 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18629 | |
| 18630 | MockWrite("GET / HTTP/1.1\r\n" |
| 18631 | "Host: www.example.org\r\n" |
| 18632 | "Connection: keep-alive\r\n\r\n"), |
| 18633 | }; |
| 18634 | |
| 18635 | MockRead data_reads1[] = { |
| 18636 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18637 | |
| 18638 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18639 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18640 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18641 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18642 | MockRead(SYNCHRONOUS, OK), |
| 18643 | }; |
| 18644 | |
| 18645 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18647 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18648 | ssl.ssl_info.cert = |
| 18649 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18650 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18651 | ssl.ssl_info.cert_status = 0; |
| 18652 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18653 | |
| 18654 | TestCompletionCallback callback1; |
| 18655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18656 | |
| 18657 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18659 | |
| 18660 | rv = callback1.WaitForResult(); |
| 18661 | EXPECT_THAT(rv, IsOk()); |
| 18662 | |
| 18663 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18664 | ASSERT_TRUE(response); |
| 18665 | EXPECT_EQ(200, response->headers->response_code()); |
| 18666 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18667 | |
| 18668 | // No NEL header was set. |
| 18669 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18670 | } |
| 18671 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18672 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18673 | RequestPolicy(); |
| 18674 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18675 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18676 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18677 | header.origin); |
| 18678 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18679 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18680 | } |
| 18681 | |
| 18682 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18683 | DontProcessNelHeaderInvalidHttps) { |
| 18684 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18685 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18686 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18687 | histograms.ExpectBucketCount( |
| 18688 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18689 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18690 | 1); |
| 18691 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18692 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18693 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18694 | RequestPolicy(); |
| 18695 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18696 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18697 | } |
| 18698 | |
| 18699 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18700 | CreateReportErrorAfterStart) { |
| 18701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18702 | auto trans = |
| 18703 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18704 | |
| 18705 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18706 | StaticSocketDataProvider data; |
| 18707 | data.set_connect_data(mock_connect); |
| 18708 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18709 | |
| 18710 | TestCompletionCallback callback; |
| 18711 | |
| 18712 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18713 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18714 | |
| 18715 | trans.reset(); |
| 18716 | |
| 18717 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18718 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18719 | IPAddress() /* server_ip */); |
| 18720 | } |
| 18721 | |
| 18722 | // Same as above except the error is ASYNC |
| 18723 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18724 | CreateReportErrorAfterStartAsync) { |
| 18725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18726 | auto trans = |
| 18727 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18728 | |
| 18729 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18730 | StaticSocketDataProvider data; |
| 18731 | data.set_connect_data(mock_connect); |
| 18732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18733 | |
| 18734 | TestCompletionCallback callback; |
| 18735 | |
| 18736 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18737 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18738 | |
| 18739 | trans.reset(); |
| 18740 | |
| 18741 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18742 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18743 | IPAddress() /* server_ip */); |
| 18744 | } |
| 18745 | |
| 18746 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18747 | CreateReportReadBodyError) { |
| 18748 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18749 | MockWrite data_writes[] = { |
| 18750 | MockWrite("GET / HTTP/1.1\r\n" |
| 18751 | "Host: www.example.org\r\n" |
| 18752 | "Connection: keep-alive\r\n"), |
| 18753 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18754 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18755 | MockRead data_reads[] = { |
| 18756 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18757 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18758 | MockRead("hello world"), |
| 18759 | MockRead(SYNCHRONOUS, OK), |
| 18760 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18761 | |
| 18762 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18763 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18764 | |
| 18765 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18766 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18767 | |
| 18768 | // Log start time |
| 18769 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18770 | |
| 18771 | TestCompletionCallback callback; |
| 18772 | auto session = CreateSession(&session_deps_); |
| 18773 | auto trans = |
| 18774 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18775 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18776 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18777 | |
| 18778 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18779 | ASSERT_TRUE(response); |
| 18780 | |
| 18781 | EXPECT_TRUE(response->headers); |
| 18782 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18783 | |
| 18784 | std::string response_data; |
| 18785 | rv = ReadTransaction(trans.get(), &response_data); |
| 18786 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18787 | |
| 18788 | trans.reset(); |
| 18789 | |
| 18790 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18791 | |
| 18792 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18793 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18794 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18795 | network_error_logging_service()->errors()[0]; |
| 18796 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18797 | } |
| 18798 | |
| 18799 | // Same as above except the final read is ASYNC. |
| 18800 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18801 | CreateReportReadBodyErrorAsync) { |
| 18802 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18803 | MockWrite data_writes[] = { |
| 18804 | MockWrite("GET / HTTP/1.1\r\n" |
| 18805 | "Host: www.example.org\r\n" |
| 18806 | "Connection: keep-alive\r\n"), |
| 18807 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18808 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18809 | MockRead data_reads[] = { |
| 18810 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18811 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18812 | MockRead("hello world"), |
| 18813 | MockRead(ASYNC, OK), |
| 18814 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18815 | |
| 18816 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18817 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18818 | |
| 18819 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18820 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18821 | |
| 18822 | // Log start time |
| 18823 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18824 | |
| 18825 | TestCompletionCallback callback; |
| 18826 | auto session = CreateSession(&session_deps_); |
| 18827 | auto trans = |
| 18828 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18829 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18830 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18831 | |
| 18832 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18833 | ASSERT_TRUE(response); |
| 18834 | |
| 18835 | EXPECT_TRUE(response->headers); |
| 18836 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18837 | |
| 18838 | std::string response_data; |
| 18839 | rv = ReadTransaction(trans.get(), &response_data); |
| 18840 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18841 | |
| 18842 | trans.reset(); |
| 18843 | |
| 18844 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18845 | |
| 18846 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18847 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18848 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18849 | network_error_logging_service()->errors()[0]; |
| 18850 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18851 | } |
| 18852 | |
| 18853 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18854 | CreateReportRestartWithAuth) { |
| 18855 | std::string extra_header_string = extra_headers_.ToString(); |
| 18856 | static const base::TimeDelta kSleepDuration = |
| 18857 | base::TimeDelta::FromMilliseconds(10); |
| 18858 | |
| 18859 | MockWrite data_writes1[] = { |
| 18860 | MockWrite("GET / HTTP/1.1\r\n" |
| 18861 | "Host: www.example.org\r\n" |
| 18862 | "Connection: keep-alive\r\n"), |
| 18863 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18864 | }; |
| 18865 | |
| 18866 | MockRead data_reads1[] = { |
| 18867 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18868 | // Give a couple authenticate options (only the middle one is actually |
| 18869 | // supported). |
| 18870 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18871 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18872 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18873 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18874 | // Large content-length -- won't matter, as connection will be reset. |
| 18875 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18876 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18877 | }; |
| 18878 | |
| 18879 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18880 | // be issuing -- the final header line contains the credentials. |
| 18881 | MockWrite data_writes2[] = { |
| 18882 | MockWrite("GET / HTTP/1.1\r\n" |
| 18883 | "Host: www.example.org\r\n" |
| 18884 | "Connection: keep-alive\r\n" |
| 18885 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18886 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18887 | }; |
| 18888 | |
| 18889 | // Lastly, the server responds with the actual content. |
| 18890 | MockRead data_reads2[] = { |
| 18891 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18892 | MockRead("hello world"), |
| 18893 | MockRead(SYNCHRONOUS, OK), |
| 18894 | }; |
| 18895 | |
| 18896 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18897 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18899 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18900 | |
| 18901 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18903 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18905 | |
| 18906 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18907 | base::TimeTicks restart_time; |
| 18908 | |
| 18909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18910 | auto trans = |
| 18911 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18912 | |
| 18913 | TestCompletionCallback callback1; |
| 18914 | |
| 18915 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18916 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18917 | |
| 18918 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18919 | |
| 18920 | TestCompletionCallback callback2; |
| 18921 | |
| 18922 | // Wait 10 ms then restart with auth |
| 18923 | FastForwardBy(kSleepDuration); |
| 18924 | restart_time = base::TimeTicks::Now(); |
| 18925 | rv = |
| 18926 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18927 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18928 | |
| 18929 | std::string response_data; |
| 18930 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18931 | EXPECT_EQ("hello world", response_data); |
| 18932 | |
| 18933 | trans.reset(); |
| 18934 | |
| 18935 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18936 | // retry. Note that we don't report the error draining the body, as the first |
| 18937 | // request already generated a report for the auth challenge. |
| 18938 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18939 | |
| 18940 | // Check error report contents |
| 18941 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18942 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18943 | |
| 18944 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18945 | network_error_logging_service()->errors()[0]; |
| 18946 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18947 | network_error_logging_service()->errors()[1]; |
| 18948 | |
| 18949 | // Sanity-check elapsed time values |
| 18950 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18951 | // Check that the start time is refreshed when restarting with auth. |
| 18952 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18953 | } |
| 18954 | |
| 18955 | // Same as above, except draining the body before restarting fails |
| 18956 | // asynchronously. |
| 18957 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18958 | CreateReportRestartWithAuthAsync) { |
| 18959 | std::string extra_header_string = extra_headers_.ToString(); |
| 18960 | static const base::TimeDelta kSleepDuration = |
| 18961 | base::TimeDelta::FromMilliseconds(10); |
| 18962 | |
| 18963 | MockWrite data_writes1[] = { |
| 18964 | MockWrite("GET / HTTP/1.1\r\n" |
| 18965 | "Host: www.example.org\r\n" |
| 18966 | "Connection: keep-alive\r\n"), |
| 18967 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18968 | }; |
| 18969 | |
| 18970 | MockRead data_reads1[] = { |
| 18971 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18972 | // Give a couple authenticate options (only the middle one is actually |
| 18973 | // supported). |
| 18974 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18975 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18976 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18977 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18978 | // Large content-length -- won't matter, as connection will be reset. |
| 18979 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18980 | MockRead(ASYNC, ERR_FAILED), |
| 18981 | }; |
| 18982 | |
| 18983 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18984 | // be issuing -- the final header line contains the credentials. |
| 18985 | MockWrite data_writes2[] = { |
| 18986 | MockWrite("GET / HTTP/1.1\r\n" |
| 18987 | "Host: www.example.org\r\n" |
| 18988 | "Connection: keep-alive\r\n" |
| 18989 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18990 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18991 | }; |
| 18992 | |
| 18993 | // Lastly, the server responds with the actual content. |
| 18994 | MockRead data_reads2[] = { |
| 18995 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18996 | MockRead("hello world"), |
| 18997 | MockRead(SYNCHRONOUS, OK), |
| 18998 | }; |
| 18999 | |
| 19000 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19001 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19002 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19003 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19004 | |
| 19005 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19007 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19009 | |
| 19010 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19011 | base::TimeTicks restart_time; |
| 19012 | |
| 19013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19014 | auto trans = |
| 19015 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19016 | |
| 19017 | TestCompletionCallback callback1; |
| 19018 | |
| 19019 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19020 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19021 | |
| 19022 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19023 | |
| 19024 | TestCompletionCallback callback2; |
| 19025 | |
| 19026 | // Wait 10 ms then restart with auth |
| 19027 | FastForwardBy(kSleepDuration); |
| 19028 | restart_time = base::TimeTicks::Now(); |
| 19029 | rv = |
| 19030 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19031 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19032 | |
| 19033 | std::string response_data; |
| 19034 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19035 | EXPECT_EQ("hello world", response_data); |
| 19036 | |
| 19037 | trans.reset(); |
| 19038 | |
| 19039 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 19040 | // retry. Note that we don't report the error draining the body, as the first |
| 19041 | // request already generated a report for the auth challenge. |
| 19042 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 19043 | |
| 19044 | // Check error report contents |
| 19045 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 19046 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 19047 | |
| 19048 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19049 | network_error_logging_service()->errors()[0]; |
| 19050 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19051 | network_error_logging_service()->errors()[1]; |
| 19052 | |
| 19053 | // Sanity-check elapsed time values |
| 19054 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 19055 | // Check that the start time is refreshed when restarting with auth. |
| 19056 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19057 | } |
| 19058 | |
| 19059 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19060 | CreateReportRetryKeepAliveConnectionReset) { |
| 19061 | std::string extra_header_string = extra_headers_.ToString(); |
| 19062 | MockWrite data_writes1[] = { |
| 19063 | MockWrite("GET / HTTP/1.1\r\n" |
| 19064 | "Host: www.example.org\r\n" |
| 19065 | "Connection: keep-alive\r\n"), |
| 19066 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19067 | MockWrite("GET / HTTP/1.1\r\n" |
| 19068 | "Host: www.example.org\r\n" |
| 19069 | "Connection: keep-alive\r\n"), |
| 19070 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19071 | }; |
| 19072 | |
| 19073 | MockRead data_reads1[] = { |
| 19074 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19075 | MockRead("hello"), |
| 19076 | // Connection is reset |
| 19077 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 19078 | }; |
| 19079 | |
| 19080 | // Successful retry |
| 19081 | MockRead data_reads2[] = { |
| 19082 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19083 | MockRead("world"), |
| 19084 | MockRead(ASYNC, OK), |
| 19085 | }; |
| 19086 | |
| 19087 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19088 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19090 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19091 | |
| 19092 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19094 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19095 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19096 | |
| 19097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19098 | auto trans1 = |
| 19099 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19100 | |
| 19101 | TestCompletionCallback callback1; |
| 19102 | |
| 19103 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19104 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19105 | |
| 19106 | std::string response_data; |
| 19107 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19108 | EXPECT_EQ("hello", response_data); |
| 19109 | |
| 19110 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19111 | |
| 19112 | auto trans2 = |
| 19113 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19114 | |
| 19115 | TestCompletionCallback callback2; |
| 19116 | |
| 19117 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19118 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19119 | |
| 19120 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19121 | EXPECT_EQ("world", response_data); |
| 19122 | |
| 19123 | trans1.reset(); |
| 19124 | trans2.reset(); |
| 19125 | |
| 19126 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19127 | // the second request, then an OK report from the successful retry. |
| 19128 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19129 | |
| 19130 | // Check error report contents |
| 19131 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19132 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19133 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19134 | } |
| 19135 | |
| 19136 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19137 | CreateReportRetryKeepAlive408) { |
| 19138 | std::string extra_header_string = extra_headers_.ToString(); |
| 19139 | MockWrite data_writes1[] = { |
| 19140 | MockWrite("GET / HTTP/1.1\r\n" |
| 19141 | "Host: www.example.org\r\n" |
| 19142 | "Connection: keep-alive\r\n"), |
| 19143 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19144 | MockWrite("GET / HTTP/1.1\r\n" |
| 19145 | "Host: www.example.org\r\n" |
| 19146 | "Connection: keep-alive\r\n"), |
| 19147 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19148 | }; |
| 19149 | |
| 19150 | MockRead data_reads1[] = { |
| 19151 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19152 | MockRead("hello"), |
| 19153 | // 408 Request Timeout |
| 19154 | MockRead(SYNCHRONOUS, |
| 19155 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19156 | "Connection: Keep-Alive\r\n" |
| 19157 | "Content-Length: 6\r\n\r\n" |
| 19158 | "Pickle"), |
| 19159 | }; |
| 19160 | |
| 19161 | // Successful retry |
| 19162 | MockRead data_reads2[] = { |
| 19163 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19164 | MockRead("world"), |
| 19165 | MockRead(ASYNC, OK), |
| 19166 | }; |
| 19167 | |
| 19168 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19169 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19170 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19171 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19172 | |
| 19173 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19175 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19177 | |
| 19178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19179 | auto trans1 = |
| 19180 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19181 | |
| 19182 | TestCompletionCallback callback1; |
| 19183 | |
| 19184 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19185 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19186 | |
| 19187 | std::string response_data; |
| 19188 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19189 | EXPECT_EQ("hello", response_data); |
| 19190 | |
| 19191 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19192 | |
| 19193 | auto trans2 = |
| 19194 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19195 | |
| 19196 | TestCompletionCallback callback2; |
| 19197 | |
| 19198 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19199 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19200 | |
| 19201 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19202 | EXPECT_EQ("world", response_data); |
| 19203 | |
| 19204 | trans1.reset(); |
| 19205 | trans2.reset(); |
| 19206 | |
| 19207 | // One 200 report from first request, then a 408 report from |
| 19208 | // the second request, then a 200 report from the successful retry. |
| 19209 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19210 | |
| 19211 | // Check error report contents |
| 19212 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19213 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19214 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19215 | } |
| 19216 | |
| 19217 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19218 | CreateReportRetry421WithoutConnectionPooling) { |
| 19219 | // Two hosts resolve to the same IP address. |
| 19220 | const std::string ip_addr = "1.2.3.4"; |
| 19221 | IPAddress ip; |
| 19222 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19223 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19224 | |
| 19225 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19226 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19227 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19228 | |
| 19229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19230 | |
| 19231 | // Two requests on the first connection. |
| 19232 | spdy::SpdySerializedFrame req1( |
| 19233 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19234 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19235 | spdy::SpdySerializedFrame req2( |
| 19236 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19237 | spdy::SpdySerializedFrame rst( |
| 19238 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19239 | MockWrite writes1[] = { |
| 19240 | CreateMockWrite(req1, 0), |
| 19241 | CreateMockWrite(req2, 3), |
| 19242 | CreateMockWrite(rst, 6), |
| 19243 | }; |
| 19244 | |
| 19245 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19246 | spdy::SpdySerializedFrame resp1( |
| 19247 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19248 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19249 | spdy::SpdyHeaderBlock response_headers; |
| 19250 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19251 | spdy::SpdySerializedFrame resp2( |
| 19252 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19253 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19254 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19255 | |
| 19256 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19257 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19258 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19259 | |
| 19260 | AddSSLSocketData(); |
| 19261 | |
| 19262 | // Retry the second request on a second connection. |
| 19263 | SpdyTestUtil spdy_util2; |
| 19264 | spdy::SpdySerializedFrame req3( |
| 19265 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19266 | MockWrite writes2[] = { |
| 19267 | CreateMockWrite(req3, 0), |
| 19268 | }; |
| 19269 | |
| 19270 | spdy::SpdySerializedFrame resp3( |
| 19271 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19272 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19273 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19274 | MockRead(ASYNC, 0, 3)}; |
| 19275 | |
| 19276 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19277 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19278 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19279 | |
| 19280 | AddSSLSocketData(); |
| 19281 | |
| 19282 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19283 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19284 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19285 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19286 | |
| 19287 | HttpRequestInfo request1; |
| 19288 | request1.method = "GET"; |
| 19289 | request1.url = GURL("https://www.example.org/"); |
| 19290 | request1.load_flags = 0; |
| 19291 | request1.traffic_annotation = |
| 19292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19293 | auto trans1 = |
| 19294 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19295 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19296 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19297 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19298 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19299 | |
| 19300 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19301 | ASSERT_TRUE(response); |
| 19302 | ASSERT_TRUE(response->headers); |
| 19303 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19304 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19305 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19306 | std::string response_data; |
| 19307 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19308 | EXPECT_EQ("hello!", response_data); |
| 19309 | |
| 19310 | trans1.reset(); |
| 19311 | |
| 19312 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19313 | |
| 19314 | HttpRequestInfo request2; |
| 19315 | request2.method = "GET"; |
| 19316 | request2.url = GURL("https://mail.example.org/"); |
| 19317 | request2.load_flags = 0; |
| 19318 | request2.traffic_annotation = |
| 19319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19320 | auto trans2 = |
| 19321 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19322 | |
| 19323 | BoundTestNetLog log; |
| 19324 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19325 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19326 | |
| 19327 | response = trans2->GetResponseInfo(); |
| 19328 | ASSERT_TRUE(response); |
| 19329 | ASSERT_TRUE(response->headers); |
| 19330 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19331 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19332 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19333 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19334 | EXPECT_EQ("hello!", response_data); |
| 19335 | |
| 19336 | trans2.reset(); |
| 19337 | |
| 19338 | // One 200 report from the first request, then a 421 report from the |
| 19339 | // second request, then a 200 report from the successful retry. |
| 19340 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19341 | |
| 19342 | // Check error report contents |
| 19343 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19344 | network_error_logging_service()->errors()[0]; |
| 19345 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19346 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19347 | EXPECT_EQ("", error1.user_agent); |
| 19348 | EXPECT_EQ(ip, error1.server_ip); |
| 19349 | EXPECT_EQ("h2", error1.protocol); |
| 19350 | EXPECT_EQ("GET", error1.method); |
| 19351 | EXPECT_EQ(200, error1.status_code); |
| 19352 | EXPECT_EQ(OK, error1.type); |
| 19353 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19354 | |
| 19355 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19356 | network_error_logging_service()->errors()[1]; |
| 19357 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19358 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19359 | EXPECT_EQ("", error2.user_agent); |
| 19360 | EXPECT_EQ(ip, error2.server_ip); |
| 19361 | EXPECT_EQ("h2", error2.protocol); |
| 19362 | EXPECT_EQ("GET", error2.method); |
| 19363 | EXPECT_EQ(421, error2.status_code); |
| 19364 | EXPECT_EQ(OK, error2.type); |
| 19365 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19366 | |
| 19367 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19368 | network_error_logging_service()->errors()[2]; |
| 19369 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19370 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19371 | EXPECT_EQ("", error3.user_agent); |
| 19372 | EXPECT_EQ(ip, error3.server_ip); |
| 19373 | EXPECT_EQ("h2", error3.protocol); |
| 19374 | EXPECT_EQ("GET", error3.method); |
| 19375 | EXPECT_EQ(200, error3.status_code); |
| 19376 | EXPECT_EQ(OK, error3.type); |
| 19377 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19378 | } |
| 19379 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19380 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19381 | CreateReportCancelAfterStart) { |
| 19382 | StaticSocketDataProvider data; |
| 19383 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19384 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19385 | |
| 19386 | TestCompletionCallback callback; |
| 19387 | auto session = CreateSession(&session_deps_); |
| 19388 | auto trans = |
| 19389 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19390 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19391 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19392 | |
| 19393 | // Cancel after start. |
| 19394 | trans.reset(); |
| 19395 | |
| 19396 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19397 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19398 | IPAddress() /* server_ip */); |
| 19399 | } |
| 19400 | |
| 19401 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19402 | CreateReportCancelBeforeReadingBody) { |
| 19403 | std::string extra_header_string = extra_headers_.ToString(); |
| 19404 | MockWrite data_writes[] = { |
| 19405 | MockWrite("GET / HTTP/1.1\r\n" |
| 19406 | "Host: www.example.org\r\n" |
| 19407 | "Connection: keep-alive\r\n"), |
| 19408 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19409 | }; |
| 19410 | MockRead data_reads[] = { |
| 19411 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19412 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19413 | }; |
| 19414 | |
| 19415 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19416 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19417 | |
| 19418 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19420 | |
| 19421 | TestCompletionCallback callback; |
| 19422 | auto session = CreateSession(&session_deps_); |
| 19423 | auto trans = |
| 19424 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19425 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19426 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19427 | |
| 19428 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19429 | ASSERT_TRUE(response); |
| 19430 | |
| 19431 | EXPECT_TRUE(response->headers); |
| 19432 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19433 | |
| 19434 | // Cancel before reading the body. |
| 19435 | trans.reset(); |
| 19436 | |
| 19437 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19438 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19439 | } |
| 19440 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19441 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19442 | base::HistogramTester histograms; |
| 19443 | RequestPolicy(); |
| 19444 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19445 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19446 | |
| 19447 | // Make HTTP request |
| 19448 | std::string extra_header_string = extra_headers_.ToString(); |
| 19449 | MockRead data_reads[] = { |
| 19450 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19451 | MockRead("hello world"), |
| 19452 | MockRead(SYNCHRONOUS, OK), |
| 19453 | }; |
| 19454 | MockWrite data_writes[] = { |
| 19455 | MockWrite("GET / HTTP/1.1\r\n" |
| 19456 | "Host: www.example.org\r\n" |
| 19457 | "Connection: keep-alive\r\n"), |
| 19458 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19459 | }; |
| 19460 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19461 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19462 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19463 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19464 | // Insecure url |
| 19465 | url_ = "http://www.example.org/"; |
| 19466 | request_.url = GURL(url_); |
| 19467 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19468 | TestCompletionCallback callback; |
| 19469 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19470 | auto trans = |
| 19471 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19472 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19473 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19474 | |
| 19475 | std::string response_data; |
| 19476 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19477 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19478 | |
| 19479 | // Insecure request does not generate a report |
| 19480 | histograms.ExpectBucketCount( |
| 19481 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19482 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19483 | |
| 19484 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19485 | } |
| 19486 | |
| 19487 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19488 | DontCreateReportHttpError) { |
| 19489 | base::HistogramTester histograms; |
| 19490 | RequestPolicy(); |
| 19491 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19492 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19493 | |
| 19494 | // Make HTTP request that fails |
| 19495 | MockRead data_reads[] = { |
| 19496 | MockRead("hello world"), |
| 19497 | MockRead(SYNCHRONOUS, OK), |
| 19498 | }; |
| 19499 | |
| 19500 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19502 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19503 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19504 | request_.url = GURL(url_); |
| 19505 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19507 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19508 | auto trans = |
| 19509 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19510 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19511 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19512 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19513 | |
| 19514 | // Insecure request does not generate a report, regardless of existence of a |
| 19515 | // policy for the origin. |
| 19516 | histograms.ExpectBucketCount( |
| 19517 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19518 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19519 | |
| 19520 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19521 | } |
| 19522 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19523 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19524 | // proxy. |
| 19525 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19526 | HttpRequestInfo request; |
| 19527 | request.method = "GET"; |
| 19528 | request.url = GURL("https://www.example.org/"); |
| 19529 | request.traffic_annotation = |
| 19530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19531 | |
| 19532 | // Configure against proxy server "myproxy:70". |
| 19533 | session_deps_.proxy_resolution_service = |
| 19534 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19535 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19537 | |
| 19538 | // Since we have proxy, should try to establish tunnel. |
| 19539 | MockWrite data_writes1[] = { |
| 19540 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19541 | "Host: www.example.org:443\r\n" |
| 19542 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19543 | }; |
| 19544 | |
| 19545 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19546 | // connection. |
| 19547 | MockRead data_reads1[] = { |
| 19548 | // No credentials. |
| 19549 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19550 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19551 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19552 | }; |
| 19553 | |
| 19554 | MockWrite data_writes2[] = { |
| 19555 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19556 | // be issuing -- the final header line contains the credentials. |
| 19557 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19558 | "Host: www.example.org:443\r\n" |
| 19559 | "Proxy-Connection: keep-alive\r\n" |
| 19560 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19561 | |
| 19562 | MockWrite("GET / HTTP/1.1\r\n" |
| 19563 | "Host: www.example.org\r\n" |
| 19564 | "Connection: keep-alive\r\n\r\n"), |
| 19565 | }; |
| 19566 | |
| 19567 | MockRead data_reads2[] = { |
| 19568 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19569 | |
| 19570 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19571 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19572 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19573 | MockRead(SYNCHRONOUS, "hello"), |
| 19574 | }; |
| 19575 | |
| 19576 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19577 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19578 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19579 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19580 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19581 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19582 | |
| 19583 | TestCompletionCallback callback1; |
| 19584 | |
| 19585 | auto trans = |
| 19586 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19587 | |
| 19588 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19589 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19590 | |
| 19591 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19592 | EXPECT_EQ(407, response->headers->response_code()); |
| 19593 | |
| 19594 | std::string response_data; |
| 19595 | rv = ReadTransaction(trans.get(), &response_data); |
| 19596 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19597 | |
| 19598 | // No NEL report is generated for the 407. |
| 19599 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19600 | |
| 19601 | TestCompletionCallback callback2; |
| 19602 | |
| 19603 | rv = |
| 19604 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19605 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19606 | |
| 19607 | response = trans->GetResponseInfo(); |
| 19608 | EXPECT_EQ(200, response->headers->response_code()); |
| 19609 | |
| 19610 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19611 | EXPECT_EQ("hello", response_data); |
| 19612 | |
| 19613 | trans.reset(); |
| 19614 | |
| 19615 | // No NEL report is generated because we are behind a proxy. |
| 19616 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19617 | } |
| 19618 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19619 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19620 | ReportContainsUploadDepth) { |
| 19621 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19622 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19623 | RequestPolicy(); |
| 19624 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19625 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19626 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19627 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19628 | } |
| 19629 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19630 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19631 | std::string extra_header_string = extra_headers_.ToString(); |
| 19632 | static const base::TimeDelta kSleepDuration = |
| 19633 | base::TimeDelta::FromMilliseconds(10); |
| 19634 | |
| 19635 | std::vector<MockWrite> data_writes = { |
| 19636 | MockWrite(ASYNC, 0, |
| 19637 | "GET / HTTP/1.1\r\n" |
| 19638 | "Host: www.example.org\r\n" |
| 19639 | "Connection: keep-alive\r\n"), |
| 19640 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19641 | }; |
| 19642 | |
| 19643 | std::vector<MockRead> data_reads = { |
| 19644 | // Write one byte of the status line, followed by a pause. |
| 19645 | MockRead(ASYNC, 2, "H"), |
| 19646 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19647 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19648 | MockRead(ASYNC, 5, "hello world"), |
| 19649 | MockRead(SYNCHRONOUS, OK, 6), |
| 19650 | }; |
| 19651 | |
| 19652 | SequencedSocketData data(data_reads, data_writes); |
| 19653 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19654 | |
| 19655 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19657 | |
| 19658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19659 | |
| 19660 | auto trans = |
| 19661 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19662 | |
| 19663 | TestCompletionCallback callback; |
| 19664 | |
| 19665 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19667 | |
| 19668 | data.RunUntilPaused(); |
| 19669 | ASSERT_TRUE(data.IsPaused()); |
| 19670 | FastForwardBy(kSleepDuration); |
| 19671 | data.Resume(); |
| 19672 | |
| 19673 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19674 | |
| 19675 | std::string response_data; |
| 19676 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19677 | EXPECT_EQ("hello world", response_data); |
| 19678 | |
| 19679 | trans.reset(); |
| 19680 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19681 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19682 | |
| 19683 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19684 | |
| 19685 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19686 | network_error_logging_service()->errors()[0]; |
| 19687 | |
| 19688 | // Sanity-check elapsed time in error report |
| 19689 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19690 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19691 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19692 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19693 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 19694 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 19695 | HttpRequestInfo request; |
| 19696 | request.method = "GET"; |
| 19697 | request.url = GURL("http://example.org/"); |
| 19698 | |
| 19699 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 19700 | |
| 19701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19703 | TestCompletionCallback callback1; |
| 19704 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 19705 | |
| 19706 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 19707 | } |
| 19708 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19709 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
| 19710 | HttpRequestInfo request; |
| 19711 | request.method = "GET"; |
| 19712 | request.url = GURL("https://www.example.org/"); |
| 19713 | request.traffic_annotation = |
| 19714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19715 | |
| 19716 | MockWrite data_writes[] = { |
| 19717 | MockWrite("GET / HTTP/1.1\r\n" |
| 19718 | "Host: www.example.org\r\n" |
| 19719 | "Connection: keep-alive\r\n\r\n"), |
| 19720 | }; |
| 19721 | |
| 19722 | // The proxy responds to the connect with a 407, using a persistent |
| 19723 | // connection. |
| 19724 | MockRead data_reads[] = { |
| 19725 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19726 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19727 | MockRead(SYNCHRONOUS, "1"), |
| 19728 | }; |
| 19729 | |
| 19730 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19731 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19732 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19733 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19734 | session_deps_.enable_early_data = true; |
| 19735 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19736 | |
| 19737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19738 | |
| 19739 | TestCompletionCallback callback; |
| 19740 | auto trans = |
| 19741 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19742 | |
| 19743 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19745 | |
| 19746 | rv = callback.WaitForResult(); |
| 19747 | EXPECT_THAT(rv, IsOk()); |
| 19748 | |
| 19749 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19750 | ASSERT_TRUE(response); |
| 19751 | ASSERT_TRUE(response->headers); |
| 19752 | EXPECT_EQ(200, response->headers->response_code()); |
| 19753 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19754 | |
| 19755 | // Check that ConfirmHandshake wasn't called. |
| 19756 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 19757 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 19758 | |
| 19759 | trans.reset(); |
| 19760 | |
| 19761 | session->CloseAllConnections(); |
| 19762 | } |
| 19763 | |
| 19764 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
| 19765 | HttpRequestInfo request; |
| 19766 | request.method = "POST"; |
| 19767 | request.url = GURL("https://www.example.org/"); |
| 19768 | request.traffic_annotation = |
| 19769 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19770 | |
| 19771 | MockWrite data_writes[] = { |
| 19772 | MockWrite(SYNCHRONOUS, |
| 19773 | "POST / HTTP/1.1\r\n" |
| 19774 | "Host: www.example.org\r\n" |
| 19775 | "Connection: keep-alive\r\n" |
| 19776 | "Content-Length: 0\r\n\r\n"), |
| 19777 | }; |
| 19778 | |
| 19779 | // The proxy responds to the connect with a 407, using a persistent |
| 19780 | // connection. |
| 19781 | MockRead data_reads[] = { |
| 19782 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19783 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19784 | MockRead(SYNCHRONOUS, "1"), |
| 19785 | }; |
| 19786 | |
| 19787 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19789 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19790 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19791 | session_deps_.enable_early_data = true; |
| 19792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19793 | |
| 19794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19795 | |
| 19796 | TestCompletionCallback callback; |
| 19797 | auto trans = |
| 19798 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19799 | |
| 19800 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19802 | |
| 19803 | rv = callback.WaitForResult(); |
| 19804 | EXPECT_THAT(rv, IsOk()); |
| 19805 | |
| 19806 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19807 | ASSERT_TRUE(response); |
| 19808 | ASSERT_TRUE(response->headers); |
| 19809 | EXPECT_EQ(200, response->headers->response_code()); |
| 19810 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19811 | |
| 19812 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19813 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19814 | |
| 19815 | trans.reset(); |
| 19816 | |
| 19817 | session->CloseAllConnections(); |
| 19818 | } |
| 19819 | |
| 19820 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 19821 | HttpRequestInfo request; |
| 19822 | request.method = "POST"; |
| 19823 | request.url = GURL("https://www.example.org/"); |
| 19824 | request.traffic_annotation = |
| 19825 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19826 | |
| 19827 | MockWrite data_writes[] = { |
| 19828 | MockWrite(ASYNC, |
| 19829 | "POST / HTTP/1.1\r\n" |
| 19830 | "Host: www.example.org\r\n" |
| 19831 | "Connection: keep-alive\r\n" |
| 19832 | "Content-Length: 0\r\n\r\n"), |
| 19833 | }; |
| 19834 | |
| 19835 | // The proxy responds to the connect with a 407, using a persistent |
| 19836 | // connection. |
| 19837 | MockRead data_reads[] = { |
| 19838 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19839 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19840 | MockRead(SYNCHRONOUS, "1"), |
| 19841 | }; |
| 19842 | |
| 19843 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19845 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19846 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19847 | session_deps_.enable_early_data = true; |
| 19848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19849 | |
| 19850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19851 | |
| 19852 | TestCompletionCallback callback; |
| 19853 | auto trans = |
| 19854 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19855 | |
| 19856 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19858 | |
| 19859 | rv = callback.WaitForResult(); |
| 19860 | EXPECT_THAT(rv, IsOk()); |
| 19861 | |
| 19862 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19863 | ASSERT_TRUE(response); |
| 19864 | ASSERT_TRUE(response->headers); |
| 19865 | EXPECT_EQ(200, response->headers->response_code()); |
| 19866 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19867 | |
| 19868 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19869 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19870 | |
| 19871 | trans.reset(); |
| 19872 | |
| 19873 | session->CloseAllConnections(); |
| 19874 | } |
| 19875 | |
| 19876 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
| 19877 | HttpRequestInfo request; |
| 19878 | request.method = "POST"; |
| 19879 | request.url = GURL("https://www.example.org/"); |
| 19880 | request.traffic_annotation = |
| 19881 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19882 | |
| 19883 | MockWrite data_writes[] = { |
| 19884 | MockWrite(SYNCHRONOUS, |
| 19885 | "POST / HTTP/1.1\r\n" |
| 19886 | "Host: www.example.org\r\n" |
| 19887 | "Connection: keep-alive\r\n" |
| 19888 | "Content-Length: 0\r\n\r\n"), |
| 19889 | }; |
| 19890 | |
| 19891 | // The proxy responds to the connect with a 407, using a persistent |
| 19892 | // connection. |
| 19893 | MockRead data_reads[] = { |
| 19894 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19895 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19896 | MockRead(SYNCHRONOUS, "1"), |
| 19897 | }; |
| 19898 | |
| 19899 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19901 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19902 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19903 | session_deps_.enable_early_data = true; |
| 19904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19905 | |
| 19906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19907 | |
| 19908 | TestCompletionCallback callback; |
| 19909 | auto trans = |
| 19910 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19911 | |
| 19912 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19914 | |
| 19915 | rv = callback.WaitForResult(); |
| 19916 | EXPECT_THAT(rv, IsOk()); |
| 19917 | |
| 19918 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19919 | ASSERT_TRUE(response); |
| 19920 | ASSERT_TRUE(response->headers); |
| 19921 | EXPECT_EQ(200, response->headers->response_code()); |
| 19922 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19923 | |
| 19924 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19925 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19926 | |
| 19927 | trans.reset(); |
| 19928 | |
| 19929 | session->CloseAllConnections(); |
| 19930 | } |
| 19931 | |
| 19932 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 19933 | HttpRequestInfo request; |
| 19934 | request.method = "POST"; |
| 19935 | request.url = GURL("https://www.example.org/"); |
| 19936 | request.traffic_annotation = |
| 19937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19938 | |
| 19939 | MockWrite data_writes[] = { |
| 19940 | MockWrite(ASYNC, |
| 19941 | "POST / HTTP/1.1\r\n" |
| 19942 | "Host: www.example.org\r\n" |
| 19943 | "Connection: keep-alive\r\n" |
| 19944 | "Content-Length: 0\r\n\r\n"), |
| 19945 | }; |
| 19946 | |
| 19947 | // The proxy responds to the connect with a 407, using a persistent |
| 19948 | // connection. |
| 19949 | MockRead data_reads[] = { |
| 19950 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19951 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19952 | MockRead(SYNCHRONOUS, "1"), |
| 19953 | }; |
| 19954 | |
| 19955 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19957 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19958 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19959 | session_deps_.enable_early_data = true; |
| 19960 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19961 | |
| 19962 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19963 | |
| 19964 | TestCompletionCallback callback; |
| 19965 | auto trans = |
| 19966 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19967 | |
| 19968 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19970 | |
| 19971 | rv = callback.WaitForResult(); |
| 19972 | EXPECT_THAT(rv, IsOk()); |
| 19973 | |
| 19974 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19975 | ASSERT_TRUE(response); |
| 19976 | ASSERT_TRUE(response->headers); |
| 19977 | EXPECT_EQ(200, response->headers->response_code()); |
| 19978 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19979 | |
| 19980 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19981 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19982 | |
| 19983 | trans.reset(); |
| 19984 | |
| 19985 | session->CloseAllConnections(); |
| 19986 | } |
| 19987 | |
| 19988 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 19989 | HttpRequestInfo request; |
| 19990 | request.method = "POST"; |
| 19991 | request.url = GURL("https://www.example.org/"); |
| 19992 | request.traffic_annotation = |
| 19993 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19994 | |
| 19995 | MockWrite data_writes[] = { |
| 19996 | MockWrite("POST / HTTP/1.1\r\n" |
| 19997 | "Host: www.example.org\r\n" |
| 19998 | "Connection: keep-alive\r\n" |
| 19999 | "Content-Length: 0\r\n\r\n"), |
| 20000 | }; |
| 20001 | |
| 20002 | // The proxy responds to the connect with a 407, using a persistent |
| 20003 | // connection. |
| 20004 | MockRead data_reads[] = { |
| 20005 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20006 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20007 | MockRead(SYNCHRONOUS, "1"), |
| 20008 | }; |
| 20009 | |
| 20010 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20012 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20013 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 20014 | session_deps_.enable_early_data = true; |
| 20015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20016 | |
| 20017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20018 | |
| 20019 | TestCompletionCallback callback; |
| 20020 | auto trans = |
| 20021 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20022 | |
| 20023 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20025 | |
| 20026 | rv = callback.WaitForResult(); |
| 20027 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 20028 | |
| 20029 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20030 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20031 | |
| 20032 | trans.reset(); |
| 20033 | |
| 20034 | session->CloseAllConnections(); |
| 20035 | } |
| 20036 | |
| 20037 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 20038 | HttpRequestInfo request; |
| 20039 | request.method = "POST"; |
| 20040 | request.url = GURL("https://www.example.org/"); |
| 20041 | request.traffic_annotation = |
| 20042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20043 | |
| 20044 | MockWrite data_writes[] = { |
| 20045 | MockWrite("POST / HTTP/1.1\r\n" |
| 20046 | "Host: www.example.org\r\n" |
| 20047 | "Connection: keep-alive\r\n" |
| 20048 | "Content-Length: 0\r\n\r\n"), |
| 20049 | }; |
| 20050 | |
| 20051 | // The proxy responds to the connect with a 407, using a persistent |
| 20052 | // connection. |
| 20053 | MockRead data_reads[] = { |
| 20054 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20055 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20056 | MockRead(SYNCHRONOUS, "1"), |
| 20057 | }; |
| 20058 | |
| 20059 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20061 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20062 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 20063 | session_deps_.enable_early_data = true; |
| 20064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20065 | |
| 20066 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20067 | |
| 20068 | TestCompletionCallback callback; |
| 20069 | auto trans = |
| 20070 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20071 | |
| 20072 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20074 | |
| 20075 | rv = callback.WaitForResult(); |
| 20076 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 20077 | |
| 20078 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20079 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20080 | |
| 20081 | trans.reset(); |
| 20082 | |
| 20083 | session->CloseAllConnections(); |
| 20084 | } |
| 20085 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20086 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20087 | // and HTTP auth. This is a regression test for https://crbug.com/946406. |
| 20088 | TEST_F(HttpNetworkTransactionTest, AuthEverything) { |
| 20089 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20090 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20091 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20092 | |
| 20093 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20094 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20095 | |
| 20096 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20097 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20098 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20099 | ASSERT_TRUE(identity_proxy); |
| 20100 | |
| 20101 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20102 | cert_request_info_origin->host_and_port = |
| 20103 | HostPortPair("www.example.org", 443); |
| 20104 | |
| 20105 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20106 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20107 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20108 | ASSERT_TRUE(identity_origin); |
| 20109 | |
| 20110 | HttpRequestInfo request; |
| 20111 | request.method = "GET"; |
| 20112 | request.url = GURL("https://www.example.org/"); |
| 20113 | request.traffic_annotation = |
| 20114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20115 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20116 | // First, the client connects to the proxy, which requests a client |
| 20117 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20118 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20119 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20120 | ssl_proxy1.expected_send_client_cert = false; |
David Benjamin | 21df4d5 | 2019-04-30 22:36:59 | [diff] [blame] | 20121 | ssl_proxy1.expected_false_start_enabled = true; |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20122 | StaticSocketDataProvider data1; |
| 20123 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20125 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20126 | // The client responds with a certificate on a new connection. The handshake |
| 20127 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20128 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20129 | ssl_proxy2.expected_send_client_cert = true; |
| 20130 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 21df4d5 | 2019-04-30 22:36:59 | [diff] [blame] | 20131 | // Proxy connections with client certs disable False Start. |
| 20132 | ssl_proxy2.expected_false_start_enabled = false; |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20133 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20134 | std::vector<MockWrite> mock_writes2; |
| 20135 | std::vector<MockRead> mock_reads2; |
| 20136 | mock_writes2.emplace_back( |
| 20137 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20138 | "Host: www.example.org:443\r\n" |
| 20139 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20140 | mock_reads2.emplace_back( |
| 20141 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20142 | "Content-Length: 0\r\n" |
| 20143 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20144 | // The client retries with credentials. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20145 | mock_writes2.emplace_back( |
| 20146 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20147 | "Host: www.example.org:443\r\n" |
| 20148 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20149 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20150 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20151 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20152 | // The origin requests client certificates. |
| 20153 | SSLSocketDataProvider ssl_origin2(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20154 | ssl_origin2.cert_request_info = cert_request_info_origin.get(); |
David Benjamin | 21df4d5 | 2019-04-30 22:36:59 | [diff] [blame] | 20155 | // The origin connection is eligible for False Start, despite the proxy |
| 20156 | // connection disabling it. |
| 20157 | ssl_origin2.expected_false_start_enabled = true; |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20158 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20159 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20161 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20162 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20163 | // The client responds to the origin client certificate request on a new |
| 20164 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20165 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20166 | ssl_proxy3.expected_send_client_cert = true; |
| 20167 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 21df4d5 | 2019-04-30 22:36:59 | [diff] [blame] | 20168 | // Proxy connections with client certs disable False Start. |
| 20169 | ssl_proxy3.expected_false_start_enabled = false; |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20170 | std::vector<MockWrite> mock_writes3; |
| 20171 | std::vector<MockRead> mock_reads3; |
| 20172 | mock_writes3.emplace_back( |
| 20173 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20174 | "Host: www.example.org:443\r\n" |
| 20175 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20176 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20177 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20178 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20179 | SSLSocketDataProvider ssl_origin3(ASYNC, OK); |
| 20180 | ssl_origin3.expected_send_client_cert = true; |
| 20181 | ssl_origin3.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 21df4d5 | 2019-04-30 22:36:59 | [diff] [blame] | 20182 | // The origin connection is eligible for False Start, despite the proxy |
| 20183 | // connection disabling it. |
| 20184 | ssl_origin3.expected_false_start_enabled = true; |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20185 | // The client sends the origin HTTP request, which results in another HTTP |
| 20186 | // auth request. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20187 | mock_writes3.emplace_back( |
| 20188 | "GET / HTTP/1.1\r\n" |
| 20189 | "Host: www.example.org\r\n" |
| 20190 | "Connection: keep-alive\r\n\r\n"); |
| 20191 | mock_reads3.emplace_back( |
| 20192 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20193 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20194 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20195 | // The client retries with credentials, and the request finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20196 | mock_writes3.emplace_back( |
| 20197 | "GET / HTTP/1.1\r\n" |
| 20198 | "Host: www.example.org\r\n" |
| 20199 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20200 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20201 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20202 | mock_reads3.emplace_back( |
| 20203 | "HTTP/1.1 200 OK\r\n" |
| 20204 | "Content-Length: 0\r\n\r\n"); |
| 20205 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20206 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20207 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20209 | |
| 20210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20211 | |
| 20212 | // Start the request. |
| 20213 | TestCompletionCallback callback; |
| 20214 | auto trans = |
| 20215 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20216 | int rv = callback.GetResult( |
| 20217 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20218 | |
| 20219 | // Handle the proxy client certificate challenge. |
| 20220 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20221 | SSLCertRequestInfo* cert_request_info = |
| 20222 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20223 | ASSERT_TRUE(cert_request_info); |
| 20224 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20225 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20226 | cert_request_info_proxy->host_and_port); |
| 20227 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20228 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20229 | callback.callback())); |
| 20230 | |
| 20231 | // Handle the proxy HTTP auth challenge. |
| 20232 | ASSERT_THAT(rv, IsOk()); |
| 20233 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20234 | EXPECT_TRUE( |
| 20235 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20236 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20237 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20238 | callback.callback())); |
| 20239 | |
| 20240 | // Handle the origin client certificate challenge. |
| 20241 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20242 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20243 | ASSERT_TRUE(cert_request_info); |
| 20244 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20245 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20246 | cert_request_info_origin->host_and_port); |
| 20247 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20248 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20249 | callback.callback())); |
| 20250 | |
| 20251 | // Handle the origin HTTP auth challenge. |
| 20252 | ASSERT_THAT(rv, IsOk()); |
| 20253 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20254 | EXPECT_TRUE( |
| 20255 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20256 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20257 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20258 | callback.callback())); |
| 20259 | |
| 20260 | // The request completes. |
| 20261 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20262 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20263 | } |
| 20264 | |
| 20265 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20266 | // and HTTP auth and each HTTP auth closing the connection. This is a regression |
| 20267 | // test for https://crbug.com/946406. |
| 20268 | TEST_F(HttpNetworkTransactionTest, AuthEverythingWithConnectClose) { |
| 20269 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20270 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20271 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20272 | |
| 20273 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20274 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20275 | |
| 20276 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20277 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20278 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20279 | ASSERT_TRUE(identity_proxy); |
| 20280 | |
| 20281 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20282 | cert_request_info_origin->host_and_port = |
| 20283 | HostPortPair("www.example.org", 443); |
| 20284 | |
| 20285 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20286 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20287 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20288 | ASSERT_TRUE(identity_origin); |
| 20289 | |
| 20290 | HttpRequestInfo request; |
| 20291 | request.method = "GET"; |
| 20292 | request.url = GURL("https://www.example.org/"); |
| 20293 | request.traffic_annotation = |
| 20294 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20295 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20296 | // First, the client connects to the proxy, which requests a client |
| 20297 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20298 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20299 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20300 | ssl_proxy1.expected_send_client_cert = false; |
| 20301 | StaticSocketDataProvider data1; |
| 20302 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20303 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20304 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20305 | // The client responds with a certificate on a new connection. The handshake |
| 20306 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20307 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20308 | ssl_proxy2.expected_send_client_cert = true; |
| 20309 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20310 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20311 | std::vector<MockWrite> mock_writes2; |
| 20312 | std::vector<MockRead> mock_reads2; |
| 20313 | mock_writes2.emplace_back( |
| 20314 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20315 | "Host: www.example.org:443\r\n" |
| 20316 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20317 | mock_reads2.emplace_back( |
| 20318 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20319 | "Content-Length: 0\r\n" |
| 20320 | "Proxy-Connection: close\r\n" |
| 20321 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20322 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20323 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20325 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20326 | // The client retries with credentials on a new connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20327 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20328 | ssl_proxy3.expected_send_client_cert = true; |
| 20329 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 20330 | std::vector<MockWrite> mock_writes3; |
| 20331 | std::vector<MockRead> mock_reads3; |
| 20332 | mock_writes3.emplace_back( |
| 20333 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20334 | "Host: www.example.org:443\r\n" |
| 20335 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20336 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20337 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20338 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20339 | // The origin requests client certificates. |
| 20340 | SSLSocketDataProvider ssl_origin3(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20341 | ssl_origin3.cert_request_info = cert_request_info_origin.get(); |
| 20342 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20343 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20344 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20345 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20346 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20347 | // The client responds to the origin client certificate request on a new |
| 20348 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20349 | SSLSocketDataProvider ssl_proxy4(ASYNC, OK); |
| 20350 | ssl_proxy4.expected_send_client_cert = true; |
| 20351 | ssl_proxy4.expected_client_cert = identity_proxy->certificate(); |
| 20352 | std::vector<MockWrite> mock_writes4; |
| 20353 | std::vector<MockRead> mock_reads4; |
| 20354 | mock_writes4.emplace_back( |
| 20355 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20356 | "Host: www.example.org:443\r\n" |
| 20357 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20358 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20359 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20360 | mock_reads4.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20361 | SSLSocketDataProvider ssl_origin4(ASYNC, OK); |
| 20362 | ssl_origin4.expected_send_client_cert = true; |
| 20363 | ssl_origin4.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20364 | // The client sends the origin HTTP request, which results in another HTTP |
| 20365 | // auth request and closed connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20366 | mock_writes4.emplace_back( |
| 20367 | "GET / HTTP/1.1\r\n" |
| 20368 | "Host: www.example.org\r\n" |
| 20369 | "Connection: keep-alive\r\n\r\n"); |
| 20370 | mock_reads4.emplace_back( |
| 20371 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20372 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20373 | "Connection: close\r\n" |
| 20374 | "Content-Length: 0\r\n\r\n"); |
| 20375 | StaticSocketDataProvider data4(mock_reads4, mock_writes4); |
| 20376 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy4); |
| 20378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin4); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20379 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20380 | // The client retries with credentials on a new connection, and the request |
| 20381 | // finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20382 | SSLSocketDataProvider ssl_proxy5(ASYNC, OK); |
| 20383 | ssl_proxy5.expected_send_client_cert = true; |
| 20384 | ssl_proxy5.expected_client_cert = identity_proxy->certificate(); |
| 20385 | std::vector<MockWrite> mock_writes5; |
| 20386 | std::vector<MockRead> mock_reads5; |
| 20387 | mock_writes5.emplace_back( |
| 20388 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20389 | "Host: www.example.org:443\r\n" |
| 20390 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20391 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20392 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20393 | mock_reads5.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20394 | SSLSocketDataProvider ssl_origin5(ASYNC, OK); |
| 20395 | ssl_origin5.expected_send_client_cert = true; |
| 20396 | ssl_origin5.expected_client_cert = identity_origin->certificate(); |
| 20397 | mock_writes5.emplace_back( |
| 20398 | "GET / HTTP/1.1\r\n" |
| 20399 | "Host: www.example.org\r\n" |
| 20400 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20401 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20402 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20403 | mock_reads5.emplace_back( |
| 20404 | "HTTP/1.1 200 OK\r\n" |
| 20405 | "Connection: close\r\n" |
| 20406 | "Content-Length: 0\r\n\r\n"); |
| 20407 | StaticSocketDataProvider data5(mock_reads5, mock_writes5); |
| 20408 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy5); |
| 20410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin5); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20411 | |
| 20412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20413 | |
| 20414 | // Start the request. |
| 20415 | TestCompletionCallback callback; |
| 20416 | auto trans = |
| 20417 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20418 | int rv = callback.GetResult( |
| 20419 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20420 | |
| 20421 | // Handle the proxy client certificate challenge. |
| 20422 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20423 | SSLCertRequestInfo* cert_request_info = |
| 20424 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20425 | ASSERT_TRUE(cert_request_info); |
| 20426 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20427 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20428 | cert_request_info_proxy->host_and_port); |
| 20429 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20430 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20431 | callback.callback())); |
| 20432 | |
| 20433 | // Handle the proxy HTTP auth challenge. |
| 20434 | ASSERT_THAT(rv, IsOk()); |
| 20435 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20436 | EXPECT_TRUE( |
| 20437 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20438 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20439 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20440 | callback.callback())); |
| 20441 | |
| 20442 | // Handle the origin client certificate challenge. |
| 20443 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20444 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20445 | ASSERT_TRUE(cert_request_info); |
| 20446 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20447 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20448 | cert_request_info_origin->host_and_port); |
| 20449 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20450 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20451 | callback.callback())); |
| 20452 | |
| 20453 | // Handle the origin HTTP auth challenge. |
| 20454 | ASSERT_THAT(rv, IsOk()); |
| 20455 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20456 | EXPECT_TRUE( |
| 20457 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20458 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20459 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20460 | callback.callback())); |
| 20461 | |
| 20462 | // The request completes. |
| 20463 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20464 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 20465 | } |
| 20466 | |
| 20467 | // Test the proxy requesting HTTP auth and the server requesting TLS client |
| 20468 | // certificates. This is a regression test for https://crbug.com/946406. |
| 20469 | TEST_F(HttpNetworkTransactionTest, ProxyHTTPAndServerTLSAuth) { |
| 20470 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20471 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20472 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20473 | |
| 20474 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20475 | cert_request_info_origin->host_and_port = |
| 20476 | HostPortPair("www.example.org", 443); |
| 20477 | |
| 20478 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20479 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20480 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20481 | ASSERT_TRUE(identity_origin); |
| 20482 | |
| 20483 | HttpRequestInfo request; |
| 20484 | request.method = "GET"; |
| 20485 | request.url = GURL("https://www.example.org/"); |
| 20486 | request.traffic_annotation = |
| 20487 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20488 | |
| 20489 | // The client connects to the proxy. The handshake succeeds. |
| 20490 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 20491 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 20492 | std::vector<MockWrite> mock_writes1; |
| 20493 | std::vector<MockRead> mock_reads1; |
| 20494 | mock_writes1.emplace_back( |
| 20495 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20496 | "Host: www.example.org:443\r\n" |
| 20497 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20498 | mock_reads1.emplace_back( |
| 20499 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20500 | "Content-Length: 0\r\n" |
| 20501 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20502 | // The client retries with credentials, and the request finally succeeds. |
| 20503 | mock_writes1.emplace_back( |
| 20504 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20505 | "Host: www.example.org:443\r\n" |
| 20506 | "Proxy-Connection: keep-alive\r\n" |
| 20507 | // Authenticate as proxyuser:proxypass. |
| 20508 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20509 | mock_reads1.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20510 | // The origin requests client certificates. |
| 20511 | SSLSocketDataProvider ssl_origin1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20512 | ssl_origin1.cert_request_info = cert_request_info_origin.get(); |
| 20513 | StaticSocketDataProvider data1(mock_reads1, mock_writes1); |
| 20514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 20516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 20517 | |
| 20518 | // The client responds to the origin client certificate request on a new |
| 20519 | // connection. |
| 20520 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20521 | std::vector<MockWrite> mock_writes2; |
| 20522 | std::vector<MockRead> mock_reads2; |
| 20523 | mock_writes2.emplace_back( |
| 20524 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20525 | "Host: www.example.org:443\r\n" |
| 20526 | "Proxy-Connection: keep-alive\r\n" |
| 20527 | // Authenticate as proxyuser:proxypass. |
| 20528 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20529 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20530 | SSLSocketDataProvider ssl_origin2(ASYNC, OK); |
| 20531 | ssl_origin2.expected_send_client_cert = true; |
| 20532 | ssl_origin2.expected_client_cert = identity_origin->certificate(); |
| 20533 | // The client sends the origin HTTP request, which succeeds. |
| 20534 | mock_writes2.emplace_back( |
| 20535 | "GET / HTTP/1.1\r\n" |
| 20536 | "Host: www.example.org\r\n" |
| 20537 | "Connection: keep-alive\r\n\r\n"); |
| 20538 | mock_reads2.emplace_back( |
| 20539 | "HTTP/1.1 200 OK\r\n" |
| 20540 | "Content-Length: 0\r\n\r\n"); |
| 20541 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20542 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20543 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20544 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 20545 | |
| 20546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20547 | |
| 20548 | // Start the request. |
| 20549 | TestCompletionCallback callback; |
| 20550 | auto trans = |
| 20551 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20552 | int rv = callback.GetResult( |
| 20553 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20554 | |
| 20555 | // Handle the proxy HTTP auth challenge. |
| 20556 | ASSERT_THAT(rv, IsOk()); |
| 20557 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20558 | EXPECT_TRUE( |
| 20559 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20560 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20561 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20562 | callback.callback())); |
| 20563 | |
| 20564 | // Handle the origin client certificate challenge. |
| 20565 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20566 | SSLCertRequestInfo* cert_request_info = |
| 20567 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20568 | ASSERT_TRUE(cert_request_info); |
| 20569 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20570 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20571 | cert_request_info_origin->host_and_port); |
| 20572 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20573 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20574 | callback.callback())); |
| 20575 | |
| 20576 | // The request completes. |
| 20577 | ASSERT_THAT(rv, IsOk()); |
| 20578 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20579 | } |
| 20580 | |
David Benjamin | 6e673a8 | 2019-04-30 22:52:58 | [diff] [blame] | 20581 | // Test that socket reuse works with client certificates. |
| 20582 | TEST_F(HttpNetworkTransactionTest, ClientCertSocketReuse) { |
| 20583 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20584 | cert_request_info->host_and_port = HostPortPair("www.example.org", 443); |
| 20585 | |
| 20586 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 20587 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20588 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20589 | ASSERT_TRUE(identity); |
| 20590 | |
| 20591 | HttpRequestInfo request1; |
| 20592 | request1.method = "GET"; |
| 20593 | request1.url = GURL("https://www.example.org/a"); |
| 20594 | request1.traffic_annotation = |
| 20595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20596 | |
| 20597 | HttpRequestInfo request2; |
| 20598 | request2.method = "GET"; |
| 20599 | request2.url = GURL("https://www.example.org/b"); |
| 20600 | request2.traffic_annotation = |
| 20601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20602 | |
| 20603 | // The first connection results in a client certificate request. |
| 20604 | StaticSocketDataProvider data1; |
| 20605 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20606 | SSLSocketDataProvider ssl1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20607 | ssl1.cert_request_info = cert_request_info.get(); |
| 20608 | ssl1.expected_send_client_cert = false; |
| 20609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20610 | |
| 20611 | // The second connection succeeds and is usable for both requests. |
| 20612 | MockWrite mock_writes[] = { |
| 20613 | MockWrite("GET /a HTTP/1.1\r\n" |
| 20614 | "Host: www.example.org\r\n" |
| 20615 | "Connection: keep-alive\r\n\r\n"), |
| 20616 | MockWrite("GET /b HTTP/1.1\r\n" |
| 20617 | "Host: www.example.org\r\n" |
| 20618 | "Connection: keep-alive\r\n\r\n"), |
| 20619 | }; |
| 20620 | MockRead mock_reads[] = { |
| 20621 | MockRead("HTTP/1.1 200 OK\r\n" |
| 20622 | "Content-Length: 0\r\n\r\n"), |
| 20623 | MockRead("HTTP/1.1 200 OK\r\n" |
| 20624 | "Content-Length: 0\r\n\r\n"), |
| 20625 | }; |
| 20626 | StaticSocketDataProvider data2(mock_reads, mock_writes); |
| 20627 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20628 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20629 | ssl2.expected_send_client_cert = true; |
| 20630 | ssl2.expected_client_cert = identity->certificate(); |
| 20631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20632 | |
| 20633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20634 | |
| 20635 | // Start the first request. It succeeds after providing client certificates. |
| 20636 | TestCompletionCallback callback; |
| 20637 | auto trans = |
| 20638 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20639 | ASSERT_THAT(callback.GetResult(trans->Start(&request1, callback.callback(), |
| 20640 | NetLogWithSource())), |
| 20641 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20642 | |
| 20643 | SSLCertRequestInfo* info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20644 | ASSERT_TRUE(info); |
| 20645 | EXPECT_FALSE(info->is_proxy); |
| 20646 | EXPECT_EQ(info->host_and_port, cert_request_info->host_and_port); |
| 20647 | |
| 20648 | ASSERT_THAT(callback.GetResult(trans->RestartWithCertificate( |
| 20649 | identity->certificate(), identity->ssl_private_key(), |
| 20650 | callback.callback())), |
| 20651 | IsOk()); |
| 20652 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 20653 | |
| 20654 | // Make the second request. It completes without requesting client |
| 20655 | // certificates. |
| 20656 | trans = |
| 20657 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20658 | ASSERT_THAT(callback.GetResult(trans->Start(&request2, callback.callback(), |
| 20659 | NetLogWithSource())), |
| 20660 | IsOk()); |
| 20661 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 20662 | } |
| 20663 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 20664 | } // namespace net |