[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 | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 33 | #include "base/test/scoped_feature_list.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" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 36 | #include "base/test/task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 37 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 38 | #include "base/threading/thread_task_runner_handle.h" |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 39 | #include "build/build_config.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 40 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 41 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 42 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 43 | #include "net/base/elements_upload_data_stream.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 44 | #include "net/base/features.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 45 | #include "net/base/host_port_pair.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 46 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 47 | #include "net/base/load_timing_info.h" |
| 48 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 49 | #include "net/base/net_errors.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 50 | #include "net/base/privacy_mode.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 51 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 52 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 53 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 54 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 55 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 56 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 57 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 58 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 59 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 60 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 61 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 62 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 63 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 64 | #include "net/http/http_auth_handler_ntlm.h" |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 65 | #include "net/http/http_auth_ntlm_mechanism.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 66 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 67 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 68 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 69 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 70 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 71 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 72 | #include "net/http/http_response_info.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 73 | #include "net/http/http_server_properties.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 74 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 75 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 76 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 77 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 78 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 79 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 80 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 81 | #include "net/log/test_net_log_util.h" |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 82 | #include "net/proxy_resolution/configured_proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 83 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 84 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 85 | #include "net/proxy_resolution/proxy_info.h" |
| 86 | #include "net/proxy_resolution/proxy_resolver.h" |
| 87 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 88 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 89 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 90 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 91 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 92 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 93 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 94 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 95 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 96 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 97 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 98 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 99 | #include "net/spdy/spdy_session.h" |
| 100 | #include "net/spdy/spdy_session_pool.h" |
| 101 | #include "net/spdy/spdy_test_util_common.h" |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 102 | #include "net/ssl/client_cert_identity_test_util.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 103 | #include "net/ssl/ssl_cert_request_info.h" |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 104 | #include "net/ssl/ssl_config.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 105 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 106 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 107 | #include "net/ssl/ssl_private_key.h" |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 108 | #include "net/ssl/test_ssl_config_service.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 109 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 110 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 111 | #include "net/test/test_data_directory.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 112 | #include "net/test/test_with_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 113 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 114 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 115 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 116 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 117 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 118 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 119 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 120 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 121 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 122 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 123 | #if defined(NTLM_PORTABLE) |
| 124 | #include "base/base64.h" |
| 125 | #include "net/ntlm/ntlm_test_data.h" |
| 126 | #endif |
| 127 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 128 | #if BUILDFLAG(ENABLE_REPORTING) |
| 129 | #include "net/network_error_logging/network_error_logging_service.h" |
| 130 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 131 | #include "net/reporting/reporting_cache.h" |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 132 | #include "net/reporting/reporting_endpoint.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 133 | #include "net/reporting/reporting_header_parser.h" |
| 134 | #include "net/reporting/reporting_service.h" |
| 135 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 136 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 137 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 138 | using net::test::IsError; |
| 139 | using net::test::IsOk; |
| 140 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 141 | using base::ASCIIToUTF16; |
| 142 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 143 | using testing::AnyOf; |
| 144 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 145 | //----------------------------------------------------------------------------- |
| 146 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 147 | namespace net { |
| 148 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 149 | namespace { |
| 150 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 151 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 152 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 153 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 154 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 155 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 156 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 157 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 158 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 159 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 160 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 161 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 162 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 163 | const char kAlternativeServiceHttpHeader[] = |
| 164 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 165 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 166 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 167 | return session |
| 168 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 169 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 170 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 171 | } |
| 172 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 173 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 174 | return session |
| 175 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 176 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 177 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 180 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 181 | // a JSONified list of headers as a single string. Uses single quotes instead |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 182 | // of double quotes for easier comparison. |
| 183 | std::string GetHeaders(const base::Value& params) { |
| 184 | if (!params.is_dict()) |
| 185 | return ""; |
| 186 | const base::Value* header_list = params.FindListKey("headers"); |
| 187 | if (!header_list) |
| 188 | return ""; |
| 189 | std::string headers; |
| 190 | base::JSONWriter::Write(*header_list, &headers); |
| 191 | base::ReplaceChars(headers, "\"", "'", &headers); |
| 192 | return headers; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 196 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 197 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 199 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 200 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 201 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 202 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 203 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 206 | |
| 207 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 208 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 209 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 210 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 211 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 212 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 213 | } |
| 214 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 216 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 217 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 218 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 220 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 221 | |
| 222 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 223 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 224 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 226 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 228 | load_timing_info.send_start); |
| 229 | |
| 230 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 231 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 232 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 233 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 234 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 235 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 239 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 240 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 242 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 243 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 244 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 245 | |
| 246 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 247 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 248 | load_timing_info.proxy_resolve_end); |
| 249 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 250 | load_timing_info.send_start); |
| 251 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 252 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 253 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 254 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 255 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 256 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 260 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 261 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 262 | int connect_timing_flags) { |
| 263 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 264 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 265 | |
| 266 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 267 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 268 | load_timing_info.proxy_resolve_end); |
| 269 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 270 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 271 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 272 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 273 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 274 | load_timing_info.send_start); |
| 275 | |
| 276 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 277 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 278 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 279 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 280 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 281 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 282 | } |
| 283 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 284 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 285 | // result to return. |
| 286 | class CapturingProxyResolver : public ProxyResolver { |
| 287 | public: |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 288 | struct LookupInfo { |
| 289 | GURL url; |
| 290 | NetworkIsolationKey network_isolation_key; |
| 291 | }; |
| 292 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 293 | CapturingProxyResolver() |
| 294 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 295 | ~CapturingProxyResolver() override = default; |
| 296 | |
| 297 | int GetProxyForURL(const GURL& url, |
Matt Menke | cd522ee0 | 2019-11-13 19:53:39 | [diff] [blame] | 298 | const NetworkIsolationKey& network_isolation_key, |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 299 | ProxyInfo* results, |
| 300 | CompletionOnceCallback callback, |
| 301 | std::unique_ptr<Request>* request, |
| 302 | const NetLogWithSource& net_log) override { |
| 303 | results->UseProxyServer(proxy_server_); |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 304 | lookup_info_.push_back(LookupInfo{url, network_isolation_key}); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 305 | return OK; |
| 306 | } |
| 307 | |
| 308 | // Sets whether the resolver should use direct connections, instead of a |
| 309 | // proxy. |
| 310 | void set_proxy_server(ProxyServer proxy_server) { |
| 311 | proxy_server_ = proxy_server; |
| 312 | } |
| 313 | |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 314 | const std::vector<LookupInfo>& lookup_info() const { return lookup_info_; } |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 315 | |
| 316 | private: |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 317 | std::vector<LookupInfo> lookup_info_; |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 318 | |
| 319 | ProxyServer proxy_server_; |
| 320 | |
| 321 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 322 | }; |
| 323 | |
| 324 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 325 | public: |
| 326 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 327 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 328 | |
| 329 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 330 | std::unique_ptr<ProxyResolver>* resolver, |
| 331 | CompletionOnceCallback callback, |
| 332 | std::unique_ptr<Request>* request) override { |
| 333 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 334 | return OK; |
| 335 | } |
| 336 | |
| 337 | private: |
| 338 | ProxyResolver* resolver_; |
| 339 | }; |
| 340 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 341 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 342 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 343 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 344 | } |
| 345 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 346 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 347 | public: |
| 348 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 349 | |
| 350 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 351 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 352 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 353 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 354 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 355 | return ERR_PAC_SCRIPT_FAILED; |
| 356 | } |
| 357 | }; |
| 358 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 359 | } // namespace |
| 360 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 361 | class HttpNetworkTransactionTest : public PlatformTest, |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 362 | public WithTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 363 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 364 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 365 | // Important to restore the per-pool limit first, since the pool limit must |
| 366 | // always be greater than group limit, and the tests reduce both limits. |
| 367 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 368 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 369 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 370 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 371 | } |
| 372 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 373 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 374 | HttpNetworkTransactionTest() |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 375 | : WithTaskEnvironment(base::test::TaskEnvironment::TimeSource::MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 376 | dummy_connect_job_params_( |
| 377 | nullptr /* client_socket_factory */, |
| 378 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 379 | nullptr /* http_auth_cache */, |
| 380 | nullptr /* http_auth_handler_factory */, |
| 381 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 382 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 383 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 384 | nullptr /* proxy_delegate */, |
| 385 | nullptr /* http_user_agent_settings */, |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 386 | nullptr /* ssl_client_context */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 387 | nullptr /* socket_performance_watcher_factory */, |
| 388 | nullptr /* network_quality_estimator */, |
| 389 | nullptr /* net_log */, |
| 390 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 391 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 392 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 393 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 394 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 395 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 396 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 397 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 398 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 399 | struct SimpleGetHelperResult { |
| 400 | int rv; |
| 401 | std::string status_line; |
| 402 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 403 | int64_t total_received_bytes; |
| 404 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 405 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 406 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 407 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 408 | }; |
| 409 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 410 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 411 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 412 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 413 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 414 | // before incrementing the counter does not return a null value. |
Matt Menke | 6dc0823 | 2019-10-03 18:00:28 | [diff] [blame] | 415 | FastForwardBy(base::TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 416 | } |
| 417 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 418 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 419 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 420 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 421 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 422 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 423 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 424 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 425 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 426 | } |
| 427 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 428 | void Check100ResponseTiming(bool use_spdy); |
| 429 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 430 | // Either |write_failure| specifies a write failure or |read_failure| |
| 431 | // specifies a read failure when using a reused socket. In either case, the |
| 432 | // failure should cause the network transaction to resend the request, and the |
| 433 | // other argument should be NULL. |
| 434 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 435 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 436 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 437 | // Either |write_failure| specifies a write failure or |read_failure| |
| 438 | // specifies a read failure when using a reused socket. In either case, the |
| 439 | // failure should cause the network transaction to resend the request, and the |
| 440 | // other argument should be NULL. |
| 441 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 442 | const MockRead* read_failure, |
| 443 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 444 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 445 | SimpleGetHelperResult SimpleGetHelperForData( |
| 446 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 447 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 448 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 449 | HttpRequestInfo request; |
| 450 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 451 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 452 | request.traffic_annotation = |
| 453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 454 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 455 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 456 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 459 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 460 | for (auto* provider : providers) { |
| 461 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 462 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 464 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 465 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 466 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 467 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 469 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 470 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 471 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 472 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 473 | |
| 474 | // Even in the failure cases that use this function, connections are always |
| 475 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 476 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 477 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 478 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 479 | if (out.rv != OK) |
| 480 | return out; |
| 481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 482 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 483 | // Can't use ASSERT_* inside helper functions like this, so |
| 484 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 485 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 486 | out.rv = ERR_UNEXPECTED; |
| 487 | return out; |
| 488 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 489 | out.status_line = response->headers->GetStatusLine(); |
| 490 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 491 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 492 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 493 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 494 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 495 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 496 | EXPECT_EQ(got_endpoint, |
| 497 | out.remote_endpoint_after_start.address().size() > 0); |
| 498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 499 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 501 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 502 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 503 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 504 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 505 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 506 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 507 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 508 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 509 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 510 | EXPECT_EQ("GET / HTTP/1.1\r\n", |
| 511 | GetStringValueFromParams(entries[pos], "line")); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 512 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 513 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 514 | GetHeaders(entries[pos].params)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 516 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 517 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 518 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 520 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 521 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 522 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 523 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 524 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 525 | MockWrite data_writes[] = { |
| 526 | MockWrite("GET / HTTP/1.1\r\n" |
| 527 | "Host: www.example.org\r\n" |
| 528 | "Connection: keep-alive\r\n\r\n"), |
| 529 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 530 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 531 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 532 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 533 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 534 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 535 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 536 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 537 | } |
| 538 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 539 | void AddSSLSocketData() { |
| 540 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 541 | ssl_.ssl_info.cert = |
| 542 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 543 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 544 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 545 | } |
| 546 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 547 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 548 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 549 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 550 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 551 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 552 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 553 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 554 | base::RepeatingClosure FastForwardByCallback(base::TimeDelta delta) { |
| 555 | return base::BindRepeating(&HttpNetworkTransactionTest::FastForwardBy, |
| 556 | base::Unretained(this), delta); |
| 557 | } |
| 558 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 559 | const CommonConnectJobParams dummy_connect_job_params_; |
| 560 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 561 | // These clocks are defined here, even though they're only used in the |
| 562 | // Reporting tests below, since they need to be destroyed after |
| 563 | // |session_deps_|. |
| 564 | base::SimpleTestClock clock_; |
| 565 | base::SimpleTestTickClock tick_clock_; |
| 566 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 567 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 568 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 569 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 570 | |
| 571 | // Original socket limits. Some tests set these. Safest to always restore |
| 572 | // them once each test has been run. |
| 573 | int old_max_group_sockets_; |
| 574 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 575 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 576 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 577 | namespace { |
| 578 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 579 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 580 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 581 | BeforeHeadersSentHandler() |
| 582 | : observed_before_headers_sent_with_proxy_(false), |
| 583 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 584 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 585 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 586 | HttpRequestHeaders* request_headers) { |
| 587 | observed_before_headers_sent_ = true; |
| 588 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 589 | !proxy_info.is_quic()) { |
| 590 | return; |
| 591 | } |
| 592 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 593 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 594 | } |
| 595 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 596 | bool observed_before_headers_sent_with_proxy() const { |
| 597 | return observed_before_headers_sent_with_proxy_; |
| 598 | } |
| 599 | |
| 600 | bool observed_before_headers_sent() const { |
| 601 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | std::string observed_proxy_server_uri() const { |
| 605 | return observed_proxy_server_uri_; |
| 606 | } |
| 607 | |
| 608 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 609 | bool observed_before_headers_sent_with_proxy_; |
| 610 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 611 | std::string observed_proxy_server_uri_; |
| 612 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 613 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 614 | }; |
| 615 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 616 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 617 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 618 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 619 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 620 | const int sizeof_row = strlen(row); |
| 621 | const int num_rows = static_cast<int>( |
| 622 | ceil(static_cast<float>(size) / sizeof_row)); |
| 623 | const int sizeof_data = num_rows * sizeof_row; |
| 624 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 625 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 626 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 627 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 628 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 629 | } |
| 630 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 631 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 632 | uint64_t MockGetMSTime() { |
| 633 | // Tue, 23 May 2017 20:13:07 +0000 |
| 634 | return 131400439870000000; |
| 635 | } |
| 636 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 637 | // Alternative functions that eliminate randomness and dependency on the local |
| 638 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 639 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 640 | // This is set to 0xaa because the client challenge for testing in |
| 641 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 642 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 643 | } |
| 644 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 645 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 646 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 647 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 648 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 649 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 650 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 651 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 652 | explicit CaptureGroupIdTransportSocketPool( |
| 653 | const CommonConnectJobParams* common_connect_job_params) |
| 654 | : TransportClientSocketPool(0, |
| 655 | 0, |
| 656 | base::TimeDelta(), |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 657 | ProxyServer::Direct(), |
| 658 | false /* is_for_websockets */, |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 659 | common_connect_job_params) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 660 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 661 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 662 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 663 | } |
| 664 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 665 | bool socket_requested() const { return socket_requested_; } |
| 666 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 667 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 668 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 669 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 670 | const base::Optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 671 | RequestPriority priority, |
| 672 | const SocketTag& socket_tag, |
| 673 | ClientSocketPool::RespectLimits respect_limits, |
| 674 | ClientSocketHandle* handle, |
| 675 | CompletionOnceCallback callback, |
| 676 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 677 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 678 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 679 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 680 | return ERR_IO_PENDING; |
| 681 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 682 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 683 | ClientSocketHandle* handle, |
| 684 | bool cancel_connect_job) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 685 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 686 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 687 | int64_t generation) override {} |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 688 | void CloseIdleSockets(const char* net_log_reason_utf8) override {} |
| 689 | void CloseIdleSocketsInGroup(const ClientSocketPool::GroupId& group_id, |
| 690 | const char* net_log_reason_utf8) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 691 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 692 | size_t IdleSocketCountInGroup( |
| 693 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 694 | return 0; |
| 695 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 696 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 697 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 698 | return LOAD_STATE_IDLE; |
| 699 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 700 | |
| 701 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 702 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 703 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 704 | }; |
| 705 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 706 | //----------------------------------------------------------------------------- |
| 707 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 708 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 709 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 710 | bool CheckBasicServerAuth( |
| 711 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 712 | if (!auth_challenge) |
| 713 | return false; |
| 714 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 715 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 716 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 717 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 718 | return true; |
| 719 | } |
| 720 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 721 | bool CheckBasicSecureServerAuth( |
| 722 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
| 723 | if (!auth_challenge) |
| 724 | return false; |
| 725 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 726 | EXPECT_EQ("https://www.example.org", auth_challenge->challenger.Serialize()); |
| 727 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 728 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 729 | return true; |
| 730 | } |
| 731 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 732 | bool CheckBasicProxyAuth( |
| 733 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 734 | if (!auth_challenge) |
| 735 | return false; |
| 736 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 737 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 738 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 739 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 740 | return true; |
| 741 | } |
| 742 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 743 | bool CheckBasicSecureProxyAuth( |
| 744 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 745 | if (!auth_challenge) |
| 746 | return false; |
| 747 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 748 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 749 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 750 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 751 | return true; |
| 752 | } |
| 753 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 754 | bool CheckDigestServerAuth( |
| 755 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 756 | if (!auth_challenge) |
| 757 | return false; |
| 758 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 759 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 760 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 761 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 762 | return true; |
| 763 | } |
| 764 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 765 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 766 | bool CheckNTLMServerAuth( |
| 767 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 768 | if (!auth_challenge) |
| 769 | return false; |
| 770 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 771 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 772 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 773 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 774 | return true; |
| 775 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 776 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 777 | bool CheckNTLMProxyAuth( |
| 778 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 779 | if (!auth_challenge) |
| 780 | return false; |
| 781 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 782 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 783 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 784 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 785 | return true; |
| 786 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 787 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 788 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 789 | } // namespace |
| 790 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 791 | // TODO(950069): Add testing for frame_origin in NetworkIsolationKey |
| 792 | // using kAppendInitiatingFrameOriginToNetworkIsolationKey. |
| 793 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 794 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 795 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 797 | } |
| 798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 799 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 800 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 801 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 802 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 804 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 805 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 806 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 807 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 808 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 809 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 810 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 811 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 812 | |
| 813 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 817 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 818 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 819 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 820 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 822 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 823 | EXPECT_THAT(out.rv, IsOk()); |
| 824 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 825 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 826 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 827 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 828 | } |
| 829 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 830 | // Response with no status line, and a weird port. Should fail by default. |
| 831 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 832 | MockRead data_reads[] = { |
| 833 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 834 | }; |
| 835 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 836 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 838 | |
| 839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 840 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 841 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 842 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 843 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 844 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 845 | request.method = "GET"; |
| 846 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 847 | request.traffic_annotation = |
| 848 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 849 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 850 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 851 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 852 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 853 | } |
| 854 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 855 | // Tests that request info can be destroyed after the headers phase is complete. |
| 856 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 858 | auto trans = |
| 859 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 860 | |
| 861 | MockRead data_reads[] = { |
| 862 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 863 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 864 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 865 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 866 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 867 | |
| 868 | TestCompletionCallback callback; |
| 869 | |
| 870 | { |
| 871 | auto request = std::make_unique<HttpRequestInfo>(); |
| 872 | request->method = "GET"; |
| 873 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 874 | request->traffic_annotation = |
| 875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 876 | |
| 877 | int rv = |
| 878 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 879 | |
| 880 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 881 | } // Let request info be destroyed. |
| 882 | |
| 883 | trans.reset(); |
| 884 | } |
| 885 | |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 886 | // Test that a failure in resolving the hostname is retrievable. |
| 887 | TEST_F(HttpNetworkTransactionTest, SimpleGETHostResolutionFailure) { |
| 888 | HttpRequestInfo request; |
| 889 | request.method = "GET"; |
| 890 | request.url = GURL("http://www.example.org/"); |
| 891 | request.traffic_annotation = |
| 892 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 893 | |
| 894 | RecordingTestNetLog log; |
| 895 | MockHostResolver* resolver = new MockHostResolver(); |
| 896 | resolver->rules()->AddSimulatedTimeoutFailure("www.example.org"); |
| 897 | session_deps_.net_log = &log; |
| 898 | session_deps_.host_resolver.reset(resolver); |
| 899 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 900 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 901 | TestCompletionCallback callback; |
| 902 | |
| 903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 905 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 906 | |
| 907 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 908 | ASSERT_TRUE(response); |
| 909 | EXPECT_THAT(response->resolve_error_info.error, IsError(ERR_DNS_TIMED_OUT)); |
| 910 | } |
| 911 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 912 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 913 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 914 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 915 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 916 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 917 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 918 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 919 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 920 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 921 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 922 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 923 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 927 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 928 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 929 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 931 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 932 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 933 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 935 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 936 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 937 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 941 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 942 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 943 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 944 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 945 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 946 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 947 | EXPECT_THAT(out.rv, IsOk()); |
| 948 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 949 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 950 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 951 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 955 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 956 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 957 | MockRead("\n"), |
| 958 | MockRead("\n"), |
| 959 | MockRead("Q"), |
| 960 | MockRead("J"), |
| 961 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 962 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 963 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 964 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 965 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 966 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 967 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 968 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 969 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 973 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 974 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 975 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 976 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 977 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 978 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 979 | EXPECT_THAT(out.rv, IsOk()); |
| 980 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 981 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 982 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 983 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 984 | } |
| 985 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 986 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 987 | // persistent connection. The response should still terminate since a 204 |
| 988 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 989 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 990 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 992 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 993 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 994 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 995 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 996 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 997 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 998 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 999 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1000 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1001 | int64_t response_size = reads_size - strlen(junk); |
| 1002 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1003 | } |
| 1004 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1005 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1006 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1007 | std::string final_chunk = "0\r\n\r\n"; |
| 1008 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1009 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1010 | MockRead data_reads[] = { |
| 1011 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1012 | MockRead("5\r\nHello\r\n"), |
| 1013 | MockRead("1\r\n"), |
| 1014 | MockRead(" \r\n"), |
| 1015 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1016 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1017 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1018 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1019 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1020 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1021 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1022 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1023 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1024 | int64_t response_size = reads_size - extra_data.size(); |
| 1025 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1026 | } |
| 1027 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1028 | // Next tests deal with http://crbug.com/56344. |
| 1029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1030 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1031 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1032 | MockRead data_reads[] = { |
| 1033 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1034 | MockRead("Content-Length: 10\r\n"), |
| 1035 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1036 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1037 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1038 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1039 | } |
| 1040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1041 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1042 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1043 | MockRead data_reads[] = { |
| 1044 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1045 | MockRead("Content-Length: 5\r\n"), |
| 1046 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1047 | MockRead("Hello"), |
| 1048 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1049 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1050 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1051 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1052 | EXPECT_EQ("Hello", out.response_data); |
| 1053 | } |
| 1054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1055 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1056 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1057 | // More than 2 dupes. |
| 1058 | { |
| 1059 | MockRead data_reads[] = { |
| 1060 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1061 | MockRead("Content-Length: 5\r\n"), |
| 1062 | MockRead("Content-Length: 5\r\n"), |
| 1063 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1064 | MockRead("Hello"), |
| 1065 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1066 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1067 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1068 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1069 | EXPECT_EQ("Hello", out.response_data); |
| 1070 | } |
| 1071 | // HTTP/1.0 |
| 1072 | { |
| 1073 | MockRead data_reads[] = { |
| 1074 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1075 | MockRead("Content-Length: 5\r\n"), |
| 1076 | MockRead("Content-Length: 5\r\n"), |
| 1077 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1078 | MockRead("Hello"), |
| 1079 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1080 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1081 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1082 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1083 | EXPECT_EQ("Hello", out.response_data); |
| 1084 | } |
| 1085 | // 2 dupes and one mismatched. |
| 1086 | { |
| 1087 | MockRead data_reads[] = { |
| 1088 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1089 | MockRead("Content-Length: 10\r\n"), |
| 1090 | MockRead("Content-Length: 10\r\n"), |
| 1091 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1092 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1093 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1094 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1098 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1099 | MultipleContentLengthHeadersTransferEncoding) { |
| 1100 | MockRead data_reads[] = { |
| 1101 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1102 | MockRead("Content-Length: 666\r\n"), |
| 1103 | MockRead("Content-Length: 1337\r\n"), |
| 1104 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1105 | MockRead("5\r\nHello\r\n"), |
| 1106 | MockRead("1\r\n"), |
| 1107 | MockRead(" \r\n"), |
| 1108 | MockRead("5\r\nworld\r\n"), |
| 1109 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1110 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1111 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1112 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1113 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1114 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1115 | EXPECT_EQ("Hello world", out.response_data); |
| 1116 | } |
| 1117 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1118 | // Next tests deal with http://crbug.com/98895. |
| 1119 | |
| 1120 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1121 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1122 | MockRead data_reads[] = { |
| 1123 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1124 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1125 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1126 | MockRead("Hello"), |
| 1127 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1128 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1129 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1130 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1131 | EXPECT_EQ("Hello", out.response_data); |
| 1132 | } |
| 1133 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1134 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1135 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1136 | MockRead data_reads[] = { |
| 1137 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1138 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1139 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1140 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1141 | MockRead("Hello"), |
| 1142 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1143 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1144 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1145 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1146 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1150 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | MockRead data_reads[] = { |
| 1152 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1153 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1154 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1155 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1156 | MockRead("Hello"), |
| 1157 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1158 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1159 | EXPECT_THAT(out.rv, |
| 1160 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | } |
| 1162 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1163 | // Checks that two identical Location headers result in no error. |
| 1164 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1165 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1166 | MockRead data_reads[] = { |
| 1167 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1168 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1169 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1171 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1172 | }; |
| 1173 | |
| 1174 | HttpRequestInfo request; |
| 1175 | request.method = "GET"; |
| 1176 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1177 | request.traffic_annotation = |
| 1178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1183 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1184 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1186 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1188 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1191 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1193 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1194 | ASSERT_TRUE(response); |
| 1195 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1196 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1197 | std::string url; |
| 1198 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1199 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1200 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | } |
| 1202 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1203 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1204 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1205 | MockRead data_reads[] = { |
| 1206 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1207 | MockRead("Location: http://good.com/\r\n"), |
| 1208 | MockRead("Location: http://evil.com/\r\n"), |
| 1209 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1210 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1211 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1212 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1213 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1214 | } |
| 1215 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1216 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1217 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1218 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1219 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1221 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1222 | request.traffic_annotation = |
| 1223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1227 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1228 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1229 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1230 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1231 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1232 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1233 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1234 | "Host: www.example.org\r\n" |
| 1235 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1236 | }; |
| 1237 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1238 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1239 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1241 | // No response body because the test stops reading here. |
| 1242 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | }; |
| 1244 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1245 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1246 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1248 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1249 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1250 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | |
| 1253 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1254 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1256 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1257 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | |
| 1259 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1260 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1262 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1263 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1264 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1265 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | |
| 1267 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1268 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1269 | bool has_server_header = response->headers->EnumerateHeader( |
| 1270 | &iter, "Server", &server_header); |
| 1271 | EXPECT_TRUE(has_server_header); |
| 1272 | EXPECT_EQ("Blah", server_header); |
| 1273 | |
| 1274 | // Reading should give EOF right away, since there is no message body |
| 1275 | // (despite non-zero content-length). |
| 1276 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1277 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1278 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1279 | EXPECT_EQ("", response_data); |
| 1280 | } |
| 1281 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1282 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | |
| 1285 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1286 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1287 | MockRead("hello"), |
| 1288 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1289 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1290 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1291 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1292 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1295 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | "hello", "world" |
| 1297 | }; |
| 1298 | |
| 1299 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1300 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1302 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1303 | request.traffic_annotation = |
| 1304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1308 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1310 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | |
| 1313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1314 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1316 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1317 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1319 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1320 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1321 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | |
| 1323 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1324 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1326 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1330 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1331 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1332 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1333 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1334 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1335 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1336 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | request.method = "POST"; |
| 1338 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1339 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1340 | request.traffic_annotation = |
| 1341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1343 | // Check the upload progress returned before initialization is correct. |
| 1344 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1345 | EXPECT_EQ(0u, progress.size()); |
| 1346 | EXPECT_EQ(0u, progress.position()); |
| 1347 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1349 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1350 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1352 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1353 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1354 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1355 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1357 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1358 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1360 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1362 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
| 1365 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1366 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1368 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1369 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1371 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1372 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1373 | |
| 1374 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1375 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1376 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | } |
| 1379 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1380 | // This test is almost the same as Ignores100 above, but the response contains |
| 1381 | // 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] | 1382 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1383 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1384 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | request.method = "GET"; |
| 1386 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1387 | request.traffic_annotation = |
| 1388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1391 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1392 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1394 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1395 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1396 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1397 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1399 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1400 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1402 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1404 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1405 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | |
| 1407 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1408 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1410 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1411 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1412 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1413 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1415 | |
| 1416 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1417 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1418 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1419 | EXPECT_EQ("hello world", response_data); |
| 1420 | } |
| 1421 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1422 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1423 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1424 | base::TimeDelta::FromMilliseconds(10); |
| 1425 | |
| 1426 | HttpRequestInfo request; |
| 1427 | request.method = "GET"; |
| 1428 | request.url = GURL("http://www.foo.com/"); |
| 1429 | request.traffic_annotation = |
| 1430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1431 | |
| 1432 | std::vector<MockWrite> data_writes = { |
| 1433 | MockWrite(ASYNC, 0, |
| 1434 | "GET / HTTP/1.1\r\n" |
| 1435 | "Host: www.foo.com\r\n" |
| 1436 | "Connection: keep-alive\r\n\r\n"), |
| 1437 | }; |
| 1438 | |
| 1439 | std::vector<MockRead> data_reads = { |
| 1440 | // Write one byte of the status line, followed by a pause. |
| 1441 | MockRead(ASYNC, 1, "H"), |
| 1442 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1443 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1444 | MockRead(ASYNC, 4, "hello world"), |
| 1445 | MockRead(SYNCHRONOUS, OK, 5), |
| 1446 | }; |
| 1447 | |
| 1448 | SequencedSocketData data(data_reads, data_writes); |
| 1449 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1450 | |
| 1451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1452 | |
| 1453 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1454 | |
| 1455 | TestCompletionCallback callback; |
| 1456 | |
| 1457 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1459 | |
| 1460 | data.RunUntilPaused(); |
| 1461 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1462 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1463 | data.Resume(); |
| 1464 | |
| 1465 | rv = callback.WaitForResult(); |
| 1466 | EXPECT_THAT(rv, IsOk()); |
| 1467 | |
| 1468 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1469 | ASSERT_TRUE(response); |
| 1470 | |
| 1471 | EXPECT_TRUE(response->headers); |
| 1472 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1473 | |
| 1474 | LoadTimingInfo load_timing_info; |
| 1475 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1476 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1477 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1478 | // Ensure we didn't include the delay in the TTFB time. |
| 1479 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1480 | load_timing_info.connect_timing.connect_end); |
| 1481 | // Ensure that the mock clock advanced at all. |
| 1482 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1483 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1484 | |
| 1485 | std::string response_data; |
| 1486 | rv = ReadTransaction(&trans, &response_data); |
| 1487 | EXPECT_THAT(rv, IsOk()); |
| 1488 | EXPECT_EQ("hello world", response_data); |
| 1489 | } |
| 1490 | |
| 1491 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1492 | // info uses the first response, even if 1XX/informational. |
| 1493 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1494 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1495 | base::TimeDelta::FromMilliseconds(10); |
| 1496 | |
| 1497 | HttpRequestInfo request; |
| 1498 | request.method = "GET"; |
| 1499 | request.url = GURL("https://www.foo.com/"); |
| 1500 | request.traffic_annotation = |
| 1501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1502 | |
| 1503 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1505 | |
| 1506 | std::vector<MockWrite> data_writes; |
| 1507 | std::vector<MockRead> data_reads; |
| 1508 | |
| 1509 | spdy::SpdySerializedFrame spdy_req( |
| 1510 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1511 | |
| 1512 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1513 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1514 | spdy::SpdySerializedFrame spdy_resp1( |
| 1515 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1516 | spdy::SpdySerializedFrame spdy_resp2( |
| 1517 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1518 | spdy::SpdySerializedFrame spdy_data( |
| 1519 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1520 | |
| 1521 | if (use_spdy) { |
| 1522 | ssl.next_proto = kProtoHTTP2; |
| 1523 | |
| 1524 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1525 | |
| 1526 | data_reads = { |
| 1527 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1528 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1529 | MockRead(SYNCHRONOUS, OK, 5), |
| 1530 | }; |
| 1531 | } else { |
| 1532 | data_writes = { |
| 1533 | MockWrite(ASYNC, 0, |
| 1534 | "GET / HTTP/1.1\r\n" |
| 1535 | "Host: www.foo.com\r\n" |
| 1536 | "Connection: keep-alive\r\n\r\n"), |
| 1537 | }; |
| 1538 | |
| 1539 | data_reads = { |
| 1540 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1541 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1542 | |
| 1543 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1544 | MockRead(ASYNC, 4, "hello world"), |
| 1545 | MockRead(SYNCHRONOUS, OK, 5), |
| 1546 | }; |
| 1547 | } |
| 1548 | |
| 1549 | SequencedSocketData data(data_reads, data_writes); |
| 1550 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1551 | |
| 1552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1553 | |
| 1554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1555 | |
| 1556 | TestCompletionCallback callback; |
| 1557 | |
| 1558 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1560 | |
| 1561 | data.RunUntilPaused(); |
| 1562 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1563 | // the delay before parsing the 200 response. |
| 1564 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1565 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1566 | data.Resume(); |
| 1567 | |
| 1568 | rv = callback.WaitForResult(); |
| 1569 | EXPECT_THAT(rv, IsOk()); |
| 1570 | |
| 1571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1572 | ASSERT_TRUE(response); |
| 1573 | |
| 1574 | LoadTimingInfo load_timing_info; |
| 1575 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1576 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1577 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1578 | // Ensure we didn't include the delay in the TTFB time. |
| 1579 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1580 | load_timing_info.connect_timing.connect_end); |
| 1581 | // Ensure that the mock clock advanced at all. |
| 1582 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1583 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1584 | |
| 1585 | std::string response_data; |
| 1586 | rv = ReadTransaction(&trans, &response_data); |
| 1587 | EXPECT_THAT(rv, IsOk()); |
| 1588 | EXPECT_EQ("hello world", response_data); |
| 1589 | } |
| 1590 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1591 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1592 | Check100ResponseTiming(false /* use_spdy */); |
| 1593 | } |
| 1594 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1595 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1596 | Check100ResponseTiming(true /* use_spdy */); |
| 1597 | } |
| 1598 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1599 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1600 | HttpRequestInfo request; |
| 1601 | request.method = "POST"; |
| 1602 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1603 | request.traffic_annotation = |
| 1604 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1605 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1608 | |
| 1609 | MockRead data_reads[] = { |
| 1610 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1611 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1612 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1613 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1614 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1615 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1616 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1617 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1618 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1620 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1621 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1622 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1623 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1624 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1625 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1626 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1627 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1628 | } |
| 1629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1630 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1631 | HttpRequestInfo request; |
| 1632 | request.method = "POST"; |
| 1633 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1634 | request.traffic_annotation = |
| 1635 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1639 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1640 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1641 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1642 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1643 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1644 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1646 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1650 | |
| 1651 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1652 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1653 | } |
| 1654 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1655 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1656 | const MockWrite* write_failure, |
| 1657 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1658 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1659 | request.method = "GET"; |
| 1660 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1661 | request.traffic_annotation = |
| 1662 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1663 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 1664 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1665 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1666 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1667 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1668 | // Written data for successfully sending both requests. |
| 1669 | MockWrite data1_writes[] = { |
| 1670 | MockWrite("GET / HTTP/1.1\r\n" |
| 1671 | "Host: www.foo.com\r\n" |
| 1672 | "Connection: keep-alive\r\n\r\n"), |
| 1673 | MockWrite("GET / HTTP/1.1\r\n" |
| 1674 | "Host: www.foo.com\r\n" |
| 1675 | "Connection: keep-alive\r\n\r\n") |
| 1676 | }; |
| 1677 | |
| 1678 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1679 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1680 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1681 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1682 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1683 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1684 | |
| 1685 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1686 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1687 | data1_writes[1] = *write_failure; |
| 1688 | } else { |
| 1689 | ASSERT_TRUE(read_failure); |
| 1690 | data1_reads[2] = *read_failure; |
| 1691 | } |
| 1692 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1693 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1694 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1695 | |
| 1696 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1697 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1698 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1699 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1700 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1701 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1702 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1703 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1704 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | "hello", "world" |
| 1706 | }; |
| 1707 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1708 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1709 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1710 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1713 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1714 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1716 | |
| 1717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1718 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1719 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1720 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1721 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1722 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1723 | if (i == 0) { |
| 1724 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1725 | } else { |
| 1726 | // The second request should be using a new socket. |
| 1727 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1728 | } |
| 1729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1730 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1731 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1732 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1733 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1734 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1735 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1736 | |
| 1737 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1738 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1740 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1741 | } |
| 1742 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1743 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1744 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1745 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1746 | const MockRead* read_failure, |
| 1747 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1748 | HttpRequestInfo request; |
| 1749 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1750 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1751 | request.traffic_annotation = |
| 1752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1753 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 1754 | RecordingTestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1755 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1757 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1758 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1759 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1760 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1761 | ssl1.next_proto = kProtoHTTP2; |
| 1762 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | } |
| 1764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1766 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1767 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1768 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1769 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1770 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1771 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1772 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1773 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1774 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1775 | // HTTP/1.1 versions of the request and response. |
| 1776 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1777 | "Host: www.foo.com\r\n" |
| 1778 | "Connection: keep-alive\r\n\r\n"; |
| 1779 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1780 | const char kHttpData[] = "hello"; |
| 1781 | |
| 1782 | std::vector<MockRead> data1_reads; |
| 1783 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1784 | if (write_failure) { |
| 1785 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1786 | data1_writes.push_back(*write_failure); |
| 1787 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1788 | } else { |
| 1789 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1790 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1791 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1792 | } else { |
| 1793 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1794 | } |
| 1795 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1796 | } |
| 1797 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1798 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1800 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1801 | std::vector<MockRead> data2_reads; |
| 1802 | std::vector<MockWrite> data2_writes; |
| 1803 | |
| 1804 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1805 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1806 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1807 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1808 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1809 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1810 | } else { |
| 1811 | data2_writes.push_back( |
| 1812 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1813 | |
| 1814 | data2_reads.push_back( |
| 1815 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1816 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1817 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1818 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1819 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1820 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1821 | |
| 1822 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1823 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1824 | // Wait for the preconnect to complete. |
| 1825 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1826 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1827 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1828 | |
| 1829 | // Make the request. |
| 1830 | TestCompletionCallback callback; |
| 1831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1834 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1836 | |
| 1837 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1838 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1839 | |
| 1840 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1841 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1842 | TestLoadTimingNotReused( |
| 1843 | load_timing_info, |
| 1844 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1846 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1847 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1848 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1849 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1850 | if (response->was_fetched_via_spdy) { |
| 1851 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1852 | } else { |
| 1853 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1854 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1855 | |
| 1856 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1857 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1858 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1859 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1860 | } |
| 1861 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1862 | // Test that we do not retry indefinitely when a server sends an error like |
Bence Béky | d0d6950 | 2019-06-25 19:47:18 | [diff] [blame] | 1863 | // ERR_HTTP2_PING_FAILED, ERR_HTTP2_SERVER_REFUSED_STREAM, |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1864 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1865 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1866 | HttpRequestInfo request; |
| 1867 | request.method = "GET"; |
| 1868 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1869 | request.traffic_annotation = |
| 1870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1871 | |
| 1872 | // Check whether we give up after the third try. |
| 1873 | |
| 1874 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1875 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1876 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1877 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1878 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1879 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1880 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1881 | |
| 1882 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1883 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1884 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1885 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1886 | |
| 1887 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1888 | AddSSLSocketData(); |
| 1889 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1890 | AddSSLSocketData(); |
| 1891 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1892 | AddSSLSocketData(); |
| 1893 | |
| 1894 | TestCompletionCallback callback; |
| 1895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1897 | |
| 1898 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1900 | |
| 1901 | rv = callback.WaitForResult(); |
Bence Béky | d0d6950 | 2019-06-25 19:47:18 | [diff] [blame] | 1902 | EXPECT_THAT(rv, IsError(ERR_HTTP2_SERVER_REFUSED_STREAM)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1906 | HttpRequestInfo request; |
| 1907 | request.method = "GET"; |
| 1908 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1909 | request.traffic_annotation = |
| 1910 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1911 | |
| 1912 | // Check whether we try atleast thrice before giving up. |
| 1913 | |
| 1914 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1915 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1916 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1917 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1918 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1919 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1920 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1921 | |
| 1922 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1923 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1924 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1925 | spdy::SpdySerializedFrame spdy_data( |
| 1926 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1927 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1928 | CreateMockRead(spdy_data, 2)}; |
| 1929 | |
| 1930 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1931 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1932 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1933 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1934 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1935 | |
| 1936 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1937 | AddSSLSocketData(); |
| 1938 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1939 | AddSSLSocketData(); |
| 1940 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1941 | AddSSLSocketData(); |
| 1942 | |
| 1943 | TestCompletionCallback callback; |
| 1944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1946 | |
| 1947 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1949 | |
| 1950 | rv = callback.WaitForResult(); |
| 1951 | EXPECT_THAT(rv, IsOk()); |
| 1952 | } |
| 1953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1954 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1955 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1956 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1957 | } |
| 1958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1959 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1960 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1961 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1962 | } |
| 1963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1964 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1965 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1966 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1967 | } |
| 1968 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1969 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1970 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1971 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1972 | MockRead read_failure(SYNCHRONOUS, |
| 1973 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1974 | "Connection: Keep-Alive\r\n" |
| 1975 | "Content-Length: 6\r\n\r\n" |
| 1976 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1977 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1978 | } |
| 1979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1980 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1981 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1982 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1983 | } |
| 1984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1985 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1986 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1987 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1988 | } |
| 1989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1990 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1991 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1992 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1993 | } |
| 1994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1995 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1996 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1997 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1998 | } |
| 1999 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2000 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2001 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2002 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2003 | MockRead read_failure(SYNCHRONOUS, |
| 2004 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2005 | "Connection: Keep-Alive\r\n" |
| 2006 | "Content-Length: 6\r\n\r\n" |
| 2007 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2008 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2009 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2010 | } |
| 2011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2012 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2013 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2014 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[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, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2018 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2019 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2020 | } |
| 2021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2022 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2023 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2024 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2025 | } |
| 2026 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2027 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2028 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2029 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2030 | } |
| 2031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2032 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2033 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2035 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2036 | request.traffic_annotation = |
| 2037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2041 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2042 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2043 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2044 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2045 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2046 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2047 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2048 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2049 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2051 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2052 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2055 | |
| 2056 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2057 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2058 | |
| 2059 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2060 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2061 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | // What do various browsers do when the server closes a non-keepalive |
| 2065 | // connection without sending any response header or body? |
| 2066 | // |
| 2067 | // IE7: error page |
| 2068 | // Safari 3.1.2 (Windows): error page |
| 2069 | // Firefox 3.0.1: blank page |
| 2070 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2071 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2072 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2073 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2074 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2075 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2076 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2077 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2078 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2079 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2080 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2081 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2082 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2083 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2084 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2085 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2086 | // destructor in such situations. |
| 2087 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2088 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2089 | HttpRequestInfo request; |
| 2090 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2091 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2092 | request.traffic_annotation = |
| 2093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2094 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2095 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2096 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2097 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2098 | |
| 2099 | MockRead data_reads[] = { |
| 2100 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2101 | MockRead("Connection: keep-alive\r\n"), |
| 2102 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2103 | MockRead("hello"), |
| 2104 | MockRead(SYNCHRONOUS, 0), |
| 2105 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2106 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2108 | |
| 2109 | TestCompletionCallback callback; |
| 2110 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2111 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2112 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2113 | |
| 2114 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2115 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2116 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2117 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2118 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2119 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2120 | if (rv == ERR_IO_PENDING) |
| 2121 | rv = callback.WaitForResult(); |
| 2122 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2123 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2124 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2125 | |
| 2126 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2127 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2128 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2129 | } |
| 2130 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2131 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2132 | HttpRequestInfo request; |
| 2133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2134 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2135 | request.traffic_annotation = |
| 2136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2137 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2138 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2139 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2140 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2141 | |
| 2142 | MockRead data_reads[] = { |
| 2143 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2144 | MockRead("Connection: keep-alive\r\n"), |
| 2145 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2146 | MockRead(SYNCHRONOUS, 0), |
| 2147 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2148 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2150 | |
| 2151 | TestCompletionCallback callback; |
| 2152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2153 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2155 | |
| 2156 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2157 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2158 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2159 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2160 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2161 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2162 | if (rv == ERR_IO_PENDING) |
| 2163 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2164 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2165 | |
| 2166 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2167 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2168 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2169 | } |
| 2170 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2171 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2172 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2173 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2174 | HttpRequestInfo request; |
| 2175 | request.method = "GET"; |
| 2176 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2177 | request.traffic_annotation = |
| 2178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2179 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2180 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2181 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2183 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2184 | const char* request_data = |
| 2185 | "GET / HTTP/1.1\r\n" |
| 2186 | "Host: www.foo.com\r\n" |
| 2187 | "Connection: keep-alive\r\n\r\n"; |
| 2188 | MockWrite data_writes[] = { |
| 2189 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2190 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2191 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2192 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2193 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2194 | }; |
| 2195 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2196 | // Note that because all these reads happen in the same |
| 2197 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2198 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2199 | MockRead data_reads[] = { |
| 2200 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2201 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2202 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2203 | MockRead(ASYNC, 7, |
| 2204 | "HTTP/1.1 302 Found\r\n" |
| 2205 | "Content-Length: 0\r\n\r\n"), |
| 2206 | MockRead(ASYNC, 9, |
| 2207 | "HTTP/1.1 302 Found\r\n" |
| 2208 | "Content-Length: 5\r\n\r\n" |
| 2209 | "hello"), |
| 2210 | MockRead(ASYNC, 11, |
| 2211 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2212 | "Content-Length: 0\r\n\r\n"), |
| 2213 | MockRead(ASYNC, 13, |
| 2214 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2215 | "Content-Length: 5\r\n\r\n" |
| 2216 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2217 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2218 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2219 | // the set_busy_before_sync_reads(true) call, while the |
| 2220 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2221 | // reuseable. See http://crbug.com/544255. |
| 2222 | MockRead(ASYNC, 15, |
| 2223 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2224 | "Content-Length: 5\r\n\r\n"), |
| 2225 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2226 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2227 | MockRead(ASYNC, 18, |
| 2228 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2229 | "Content-Length: 5\r\n\r\n" |
| 2230 | "he"), |
| 2231 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2232 | |
| 2233 | // The body of the final request is actually read. |
| 2234 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2235 | MockRead(ASYNC, 22, "hello"), |
| 2236 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2237 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2238 | data.set_busy_before_sync_reads(true); |
| 2239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2240 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2241 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2242 | std::string response_lines[kNumUnreadBodies]; |
| 2243 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2244 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2245 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2246 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2247 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2248 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2249 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2250 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2251 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2252 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2253 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2254 | LoadTimingInfo load_timing_info; |
| 2255 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2256 | if (i == 0) { |
| 2257 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2258 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2259 | } else { |
| 2260 | TestLoadTimingReused(load_timing_info); |
| 2261 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2262 | } |
| 2263 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2264 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2265 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2266 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2267 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2268 | response_lines[i] = response->headers->GetStatusLine(); |
| 2269 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2270 | // Delete the transaction without reading the response bodies. Then spin |
| 2271 | // the message loop, so the response bodies are drained. |
| 2272 | trans.reset(); |
| 2273 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2274 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2275 | |
| 2276 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2277 | "HTTP/1.1 204 No Content", |
| 2278 | "HTTP/1.1 205 Reset Content", |
| 2279 | "HTTP/1.1 304 Not Modified", |
| 2280 | "HTTP/1.1 302 Found", |
| 2281 | "HTTP/1.1 302 Found", |
| 2282 | "HTTP/1.1 301 Moved Permanently", |
| 2283 | "HTTP/1.1 301 Moved Permanently", |
| 2284 | "HTTP/1.1 200 Hunky-Dory", |
| 2285 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2286 | }; |
| 2287 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2288 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2289 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2290 | |
| 2291 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2292 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2294 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2297 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2298 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2299 | ASSERT_TRUE(response); |
| 2300 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2301 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2302 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2303 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2304 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2305 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2306 | } |
| 2307 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2308 | // Sockets that receive extra data after a response is complete should not be |
| 2309 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2310 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2312 | MockWrite data_writes1[] = { |
| 2313 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2314 | "Host: www.borked.com\r\n" |
| 2315 | "Connection: keep-alive\r\n\r\n"), |
| 2316 | }; |
| 2317 | |
| 2318 | MockRead data_reads1[] = { |
| 2319 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2320 | "Connection: keep-alive\r\n" |
| 2321 | "Content-Length: 22\r\n\r\n" |
| 2322 | "This server is borked."), |
| 2323 | }; |
| 2324 | |
| 2325 | MockWrite data_writes2[] = { |
| 2326 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2327 | "Host: www.borked.com\r\n" |
| 2328 | "Connection: keep-alive\r\n\r\n"), |
| 2329 | }; |
| 2330 | |
| 2331 | MockRead data_reads2[] = { |
| 2332 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2333 | "Content-Length: 3\r\n\r\n" |
| 2334 | "foo"), |
| 2335 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2336 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2337 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2338 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2339 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2340 | |
| 2341 | TestCompletionCallback callback; |
| 2342 | HttpRequestInfo request1; |
| 2343 | request1.method = "HEAD"; |
| 2344 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2345 | request1.traffic_annotation = |
| 2346 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2347 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2348 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2349 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2350 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2351 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2352 | |
| 2353 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2354 | ASSERT_TRUE(response1); |
| 2355 | ASSERT_TRUE(response1->headers); |
| 2356 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2357 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2358 | |
| 2359 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2360 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2361 | EXPECT_EQ("", response_data1); |
| 2362 | // Deleting the transaction attempts to release the socket back into the |
| 2363 | // socket pool. |
| 2364 | trans1.reset(); |
| 2365 | |
| 2366 | HttpRequestInfo request2; |
| 2367 | request2.method = "GET"; |
| 2368 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2369 | request2.traffic_annotation = |
| 2370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2371 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2372 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2373 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2374 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2375 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | |
| 2377 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2378 | ASSERT_TRUE(response2); |
| 2379 | ASSERT_TRUE(response2->headers); |
| 2380 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2381 | |
| 2382 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2383 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2384 | EXPECT_EQ("foo", response_data2); |
| 2385 | } |
| 2386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2387 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2389 | MockWrite data_writes1[] = { |
| 2390 | MockWrite("GET / HTTP/1.1\r\n" |
| 2391 | "Host: www.borked.com\r\n" |
| 2392 | "Connection: keep-alive\r\n\r\n"), |
| 2393 | }; |
| 2394 | |
| 2395 | MockRead data_reads1[] = { |
| 2396 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2397 | "Connection: keep-alive\r\n" |
| 2398 | "Content-Length: 22\r\n\r\n" |
| 2399 | "This server is borked." |
| 2400 | "Bonus data!"), |
| 2401 | }; |
| 2402 | |
| 2403 | MockWrite data_writes2[] = { |
| 2404 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2405 | "Host: www.borked.com\r\n" |
| 2406 | "Connection: keep-alive\r\n\r\n"), |
| 2407 | }; |
| 2408 | |
| 2409 | MockRead data_reads2[] = { |
| 2410 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2411 | "Content-Length: 3\r\n\r\n" |
| 2412 | "foo"), |
| 2413 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2414 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2415 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2416 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2417 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2418 | |
| 2419 | TestCompletionCallback callback; |
| 2420 | HttpRequestInfo request1; |
| 2421 | request1.method = "GET"; |
| 2422 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2423 | request1.traffic_annotation = |
| 2424 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2425 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2426 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2427 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2428 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2429 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2430 | |
| 2431 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2432 | ASSERT_TRUE(response1); |
| 2433 | ASSERT_TRUE(response1->headers); |
| 2434 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2435 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2436 | |
| 2437 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2438 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2439 | EXPECT_EQ("This server is borked.", response_data1); |
| 2440 | // Deleting the transaction attempts to release the socket back into the |
| 2441 | // socket pool. |
| 2442 | trans1.reset(); |
| 2443 | |
| 2444 | HttpRequestInfo request2; |
| 2445 | request2.method = "GET"; |
| 2446 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2447 | request2.traffic_annotation = |
| 2448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2449 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2450 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2451 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2452 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2453 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2454 | |
| 2455 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2456 | ASSERT_TRUE(response2); |
| 2457 | ASSERT_TRUE(response2->headers); |
| 2458 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2459 | |
| 2460 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2461 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2462 | EXPECT_EQ("foo", response_data2); |
| 2463 | } |
| 2464 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2465 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2467 | MockWrite data_writes1[] = { |
| 2468 | MockWrite("GET / HTTP/1.1\r\n" |
| 2469 | "Host: www.borked.com\r\n" |
| 2470 | "Connection: keep-alive\r\n\r\n"), |
| 2471 | }; |
| 2472 | |
| 2473 | MockRead data_reads1[] = { |
| 2474 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2475 | "Connection: keep-alive\r\n" |
| 2476 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2477 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2478 | MockRead("0\r\n\r\nBonus data!"), |
| 2479 | }; |
| 2480 | |
| 2481 | MockWrite data_writes2[] = { |
| 2482 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2483 | "Host: www.borked.com\r\n" |
| 2484 | "Connection: keep-alive\r\n\r\n"), |
| 2485 | }; |
| 2486 | |
| 2487 | MockRead data_reads2[] = { |
| 2488 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2489 | "Content-Length: 3\r\n\r\n" |
| 2490 | "foo"), |
| 2491 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2492 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2493 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2494 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2495 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2496 | |
| 2497 | TestCompletionCallback callback; |
| 2498 | HttpRequestInfo request1; |
| 2499 | request1.method = "GET"; |
| 2500 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2501 | request1.traffic_annotation = |
| 2502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2503 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2504 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2505 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2506 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2507 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2508 | |
| 2509 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2510 | ASSERT_TRUE(response1); |
| 2511 | ASSERT_TRUE(response1->headers); |
| 2512 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2513 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2514 | |
| 2515 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2516 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2517 | EXPECT_EQ("This server is borked.", response_data1); |
| 2518 | // Deleting the transaction attempts to release the socket back into the |
| 2519 | // socket pool. |
| 2520 | trans1.reset(); |
| 2521 | |
| 2522 | HttpRequestInfo request2; |
| 2523 | request2.method = "GET"; |
| 2524 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2525 | request2.traffic_annotation = |
| 2526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2527 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2528 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2529 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2530 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2531 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2532 | |
| 2533 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2534 | ASSERT_TRUE(response2); |
| 2535 | ASSERT_TRUE(response2->headers); |
| 2536 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2537 | |
| 2538 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2539 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2540 | EXPECT_EQ("foo", response_data2); |
| 2541 | } |
| 2542 | |
| 2543 | // This is a little different from the others - it tests the case that the |
| 2544 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2545 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2546 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2547 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2549 | MockWrite data_writes1[] = { |
| 2550 | MockWrite("GET / HTTP/1.1\r\n" |
| 2551 | "Host: www.borked.com\r\n" |
| 2552 | "Connection: keep-alive\r\n\r\n"), |
| 2553 | }; |
| 2554 | |
| 2555 | MockRead data_reads1[] = { |
| 2556 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2557 | "Connection: keep-alive\r\n" |
| 2558 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2559 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2560 | MockRead("0\r\n\r\nBonus data!"), |
| 2561 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2562 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2563 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2564 | |
| 2565 | TestCompletionCallback callback; |
| 2566 | HttpRequestInfo request1; |
| 2567 | request1.method = "GET"; |
| 2568 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2569 | request1.traffic_annotation = |
| 2570 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2571 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2572 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2573 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2574 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2575 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2576 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2577 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2578 | ASSERT_TRUE(response1); |
| 2579 | ASSERT_TRUE(response1->headers); |
| 2580 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2581 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2582 | |
| 2583 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2584 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2585 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2586 | |
| 2587 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2588 | // socket can't be reused, rather than returning it to the socket pool. |
| 2589 | base::RunLoop().RunUntilIdle(); |
| 2590 | |
| 2591 | // There should be no idle sockets in the pool. |
| 2592 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2593 | } |
| 2594 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2595 | // Test the request-challenge-retry sequence for basic auth. |
| 2596 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2597 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2598 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2599 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2600 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2601 | request.traffic_annotation = |
| 2602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2603 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2604 | RecordingTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2605 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2608 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2609 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2610 | MockWrite( |
| 2611 | "GET / HTTP/1.1\r\n" |
| 2612 | "Host: www.example.org\r\n" |
| 2613 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2614 | }; |
| 2615 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2616 | MockRead data_reads1[] = { |
| 2617 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2618 | // Give a couple authenticate options (only the middle one is actually |
| 2619 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2620 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2621 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2622 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2623 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2624 | // Large content-length -- won't matter, as connection will be reset. |
| 2625 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2626 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2627 | }; |
| 2628 | |
| 2629 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2630 | // be issuing -- the final header line contains the credentials. |
| 2631 | MockWrite data_writes2[] = { |
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" |
| 2636 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2637 | }; |
| 2638 | |
| 2639 | // Lastly, the server responds with the actual content. |
| 2640 | MockRead data_reads2[] = { |
| 2641 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2642 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2643 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2644 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2645 | }; |
| 2646 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2647 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2648 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2649 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2650 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2651 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2652 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2654 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2656 | |
| 2657 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2658 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2659 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2660 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2661 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2662 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2663 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2664 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2665 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2666 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2667 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2668 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2669 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2670 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2671 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2673 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2675 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2677 | |
| 2678 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2679 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2680 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2681 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2682 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2683 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2684 | // The load timing after restart should have a new socket ID, and times after |
| 2685 | // those of the first load timing. |
| 2686 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2687 | load_timing_info2.connect_timing.connect_start); |
| 2688 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2689 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2690 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2691 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2692 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2693 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2695 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2696 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2697 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2698 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2699 | } |
| 2700 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2701 | // Test the request-challenge-retry sequence for basic auth. |
| 2702 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2703 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2704 | HttpRequestInfo request; |
| 2705 | request.method = "GET"; |
| 2706 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2707 | request.traffic_annotation = |
| 2708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2709 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2710 | RecordingTestNetLog log; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2711 | MockHostResolver* resolver = new MockHostResolver(); |
| 2712 | session_deps_.net_log = &log; |
| 2713 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2714 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2715 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2716 | |
| 2717 | resolver->rules()->ClearRules(); |
| 2718 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2719 | |
| 2720 | MockWrite data_writes1[] = { |
| 2721 | MockWrite("GET / HTTP/1.1\r\n" |
| 2722 | "Host: www.example.org\r\n" |
| 2723 | "Connection: keep-alive\r\n\r\n"), |
| 2724 | }; |
| 2725 | |
| 2726 | MockRead data_reads1[] = { |
| 2727 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2728 | // Give a couple authenticate options (only the middle one is actually |
| 2729 | // supported). |
| 2730 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2731 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2732 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2733 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2734 | // Large content-length -- won't matter, as connection will be reset. |
| 2735 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2736 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2737 | }; |
| 2738 | |
| 2739 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2740 | // be issuing -- the final header line contains the credentials. |
| 2741 | MockWrite data_writes2[] = { |
| 2742 | MockWrite("GET / HTTP/1.1\r\n" |
| 2743 | "Host: www.example.org\r\n" |
| 2744 | "Connection: keep-alive\r\n" |
| 2745 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2746 | }; |
| 2747 | |
| 2748 | // Lastly, the server responds with the actual content. |
| 2749 | MockRead data_reads2[] = { |
| 2750 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2751 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2752 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2753 | }; |
| 2754 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2755 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2756 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2757 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2758 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2759 | |
| 2760 | TestCompletionCallback callback1; |
| 2761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2762 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2763 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2764 | |
| 2765 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2766 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2767 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2768 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2769 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2770 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2771 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2772 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2774 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2775 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2776 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2777 | |
| 2778 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2779 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2780 | ASSERT_FALSE(endpoint.address().empty()); |
| 2781 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2782 | |
| 2783 | resolver->rules()->ClearRules(); |
| 2784 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2785 | |
| 2786 | TestCompletionCallback callback2; |
| 2787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2789 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2790 | |
| 2791 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2792 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2793 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2794 | // The load timing after restart should have a new socket ID, and times after |
| 2795 | // those of the first load timing. |
| 2796 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2797 | load_timing_info2.connect_timing.connect_start); |
| 2798 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2799 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2800 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2801 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2802 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2803 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2804 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2805 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2806 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2807 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2808 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2810 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2811 | ASSERT_FALSE(endpoint.address().empty()); |
| 2812 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2813 | } |
| 2814 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2815 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2816 | // will eventually give up. |
| 2817 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2818 | HttpRequestInfo request; |
| 2819 | request.method = "GET"; |
| 2820 | request.url = GURL("http://www.example.org/"); |
| 2821 | request.traffic_annotation = |
| 2822 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2823 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2824 | RecordingTestNetLog log; |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2825 | session_deps_.net_log = &log; |
| 2826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2828 | |
| 2829 | MockWrite data_writes[] = { |
| 2830 | MockWrite("GET / HTTP/1.1\r\n" |
| 2831 | "Host: www.example.org\r\n" |
| 2832 | "Connection: keep-alive\r\n\r\n"), |
| 2833 | }; |
| 2834 | |
| 2835 | MockRead data_reads[] = { |
| 2836 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2837 | // Give a couple authenticate options (only the middle one is actually |
| 2838 | // supported). |
| 2839 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2840 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2841 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2842 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2843 | // Large content-length -- won't matter, as connection will be reset. |
| 2844 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2845 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2846 | }; |
| 2847 | |
| 2848 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2849 | // be issuing -- the final header line contains the credentials. |
| 2850 | MockWrite data_writes_restart[] = { |
| 2851 | MockWrite("GET / HTTP/1.1\r\n" |
| 2852 | "Host: www.example.org\r\n" |
| 2853 | "Connection: keep-alive\r\n" |
| 2854 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2855 | }; |
| 2856 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2857 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2859 | |
| 2860 | TestCompletionCallback callback; |
| 2861 | int rv = callback.GetResult( |
| 2862 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2863 | |
| 2864 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2865 | for (int i = 0; i < 32; i++) { |
| 2866 | // Check the previous response was a 401. |
| 2867 | EXPECT_THAT(rv, IsOk()); |
| 2868 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2869 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2870 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2871 | |
| 2872 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2873 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2874 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2875 | data_restarts.back().get()); |
| 2876 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2877 | callback.callback())); |
| 2878 | } |
| 2879 | |
| 2880 | // After too many tries, the transaction should have given up. |
| 2881 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2882 | } |
| 2883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2884 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2885 | HttpRequestInfo request; |
| 2886 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2887 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2888 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2889 | request.traffic_annotation = |
| 2890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2891 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2893 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2894 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2895 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2896 | MockWrite( |
| 2897 | "GET / HTTP/1.1\r\n" |
| 2898 | "Host: www.example.org\r\n" |
| 2899 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2900 | }; |
| 2901 | |
| 2902 | MockRead data_reads[] = { |
| 2903 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2904 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2905 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2906 | // Large content-length -- won't matter, as connection will be reset. |
| 2907 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2908 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2909 | }; |
| 2910 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2911 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2912 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2913 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2914 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2915 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2917 | |
| 2918 | rv = callback.WaitForResult(); |
| 2919 | EXPECT_EQ(0, rv); |
| 2920 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2921 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2922 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2923 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2924 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2926 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2927 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2928 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2929 | } |
| 2930 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2931 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2932 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2933 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2934 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2935 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2936 | // reused. See http://crbug.com/544255. |
| 2937 | for (int i = 0; i < 2; ++i) { |
| 2938 | HttpRequestInfo request; |
| 2939 | request.method = "GET"; |
| 2940 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2941 | request.traffic_annotation = |
| 2942 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2943 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2944 | RecordingTestNetLog log; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2945 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2947 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2948 | MockWrite data_writes[] = { |
| 2949 | MockWrite(ASYNC, 0, |
| 2950 | "GET / HTTP/1.1\r\n" |
| 2951 | "Host: www.example.org\r\n" |
| 2952 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2954 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2955 | // be issuing -- the final header line contains the credentials. |
| 2956 | MockWrite(ASYNC, 6, |
| 2957 | "GET / HTTP/1.1\r\n" |
| 2958 | "Host: www.example.org\r\n" |
| 2959 | "Connection: keep-alive\r\n" |
| 2960 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2961 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2962 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2963 | MockRead data_reads[] = { |
| 2964 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2965 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2966 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2967 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2968 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2969 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2970 | // Lastly, the server responds with the actual content. |
| 2971 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2972 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2973 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2974 | MockRead(ASYNC, 10, "Hello"), |
| 2975 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2976 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2977 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2978 | data.set_busy_before_sync_reads(true); |
| 2979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2980 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2981 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2983 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2984 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2985 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2986 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2987 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2988 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2989 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2991 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2992 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2993 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2994 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2995 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2997 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2998 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2999 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3000 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3001 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3002 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3003 | TestLoadTimingReused(load_timing_info2); |
| 3004 | // The load timing after restart should have the same socket ID, and times |
| 3005 | // those of the first load timing. |
| 3006 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3007 | load_timing_info2.send_start); |
| 3008 | 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] | 3009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3010 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3011 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3012 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3013 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3014 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3015 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3016 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3017 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3018 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3019 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3020 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3021 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3022 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3026 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3027 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3028 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3030 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3031 | request.traffic_annotation = |
| 3032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3033 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3035 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3036 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3037 | MockWrite("GET / HTTP/1.1\r\n" |
| 3038 | "Host: www.example.org\r\n" |
| 3039 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3040 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3041 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3042 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3043 | MockWrite("GET / HTTP/1.1\r\n" |
| 3044 | "Host: www.example.org\r\n" |
| 3045 | "Connection: keep-alive\r\n" |
| 3046 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3047 | }; |
| 3048 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3049 | MockRead data_reads1[] = { |
| 3050 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3051 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3052 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3053 | |
| 3054 | // Lastly, the server responds with the actual content. |
| 3055 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3056 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3057 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3058 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3059 | }; |
| 3060 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3061 | // An incorrect reconnect would cause this to be read. |
| 3062 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3063 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3064 | }; |
| 3065 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3066 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3067 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3068 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3069 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3071 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3074 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3075 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3076 | |
| 3077 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3078 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3079 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3080 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3081 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3082 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3084 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3086 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3088 | |
| 3089 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3090 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3092 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3093 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3094 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3095 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3099 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3100 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3101 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3103 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3104 | request.traffic_annotation = |
| 3105 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3106 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3107 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3108 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3109 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3110 | MockWrite("GET / HTTP/1.1\r\n" |
| 3111 | "Host: www.example.org\r\n" |
| 3112 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3114 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3115 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3116 | MockWrite("GET / HTTP/1.1\r\n" |
| 3117 | "Host: www.example.org\r\n" |
| 3118 | "Connection: keep-alive\r\n" |
| 3119 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3120 | }; |
| 3121 | |
| 3122 | // Respond with 5 kb of response body. |
| 3123 | std::string large_body_string("Unauthorized"); |
| 3124 | large_body_string.append(5 * 1024, ' '); |
| 3125 | large_body_string.append("\r\n"); |
| 3126 | |
| 3127 | MockRead data_reads1[] = { |
| 3128 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3129 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3130 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3131 | // 5134 = 12 + 5 * 1024 + 2 |
| 3132 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3133 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3134 | |
| 3135 | // Lastly, the server responds with the actual content. |
| 3136 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3137 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3138 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3139 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3140 | }; |
| 3141 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3142 | // An incorrect reconnect would cause this to be read. |
| 3143 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3144 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3145 | }; |
| 3146 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3147 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3148 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3149 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3150 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3152 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3155 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | |
| 3158 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3161 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3162 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3163 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3165 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3167 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3168 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3169 | |
| 3170 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3171 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3173 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3174 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3175 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3176 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3180 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3181 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3182 | HttpRequestInfo request; |
| 3183 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3184 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3185 | request.traffic_annotation = |
| 3186 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3187 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3189 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3190 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3191 | MockWrite( |
| 3192 | "GET / HTTP/1.1\r\n" |
| 3193 | "Host: www.example.org\r\n" |
| 3194 | "Connection: keep-alive\r\n\r\n"), |
| 3195 | // This simulates the seemingly successful write to a closed connection |
| 3196 | // if the bug is not fixed. |
| 3197 | MockWrite( |
| 3198 | "GET / HTTP/1.1\r\n" |
| 3199 | "Host: www.example.org\r\n" |
| 3200 | "Connection: keep-alive\r\n" |
| 3201 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3202 | }; |
| 3203 | |
| 3204 | MockRead data_reads1[] = { |
| 3205 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3206 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3207 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3208 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3209 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3210 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3211 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3212 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3213 | }; |
| 3214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3215 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3216 | // be issuing -- the final header line contains the credentials. |
| 3217 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3218 | MockWrite( |
| 3219 | "GET / HTTP/1.1\r\n" |
| 3220 | "Host: www.example.org\r\n" |
| 3221 | "Connection: keep-alive\r\n" |
| 3222 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3223 | }; |
| 3224 | |
| 3225 | // Lastly, the server responds with the actual content. |
| 3226 | MockRead data_reads2[] = { |
| 3227 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3228 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3229 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3230 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3231 | }; |
| 3232 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3233 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3234 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3235 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3236 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3238 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3241 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3243 | |
| 3244 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3245 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3246 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3247 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3248 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3249 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3251 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3253 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3255 | |
| 3256 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3257 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3259 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3260 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3261 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3262 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3263 | } |
| 3264 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3265 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3266 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3267 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3268 | HttpRequestInfo request; |
| 3269 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3270 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3271 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3272 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3273 | request.traffic_annotation = |
| 3274 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3275 | |
| 3276 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3277 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3278 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3279 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3280 | RecordingBoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3281 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3282 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3283 | |
| 3284 | // Since we have proxy, should try to establish tunnel. |
| 3285 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3286 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3287 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3288 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3289 | }; |
| 3290 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3291 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3292 | // connection. |
| 3293 | MockRead data_reads1[] = { |
| 3294 | // No credentials. |
| 3295 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3296 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3297 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3298 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3299 | // Since the first connection couldn't be reused, need to establish another |
| 3300 | // once given credentials. |
| 3301 | MockWrite data_writes2[] = { |
| 3302 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3303 | // be issuing -- the final header line contains the credentials. |
| 3304 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3305 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3306 | "Proxy-Connection: keep-alive\r\n" |
| 3307 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3308 | |
| 3309 | MockWrite("GET / HTTP/1.1\r\n" |
| 3310 | "Host: www.example.org\r\n" |
| 3311 | "Connection: keep-alive\r\n\r\n"), |
| 3312 | }; |
| 3313 | |
| 3314 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3315 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3316 | |
| 3317 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3318 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3319 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3320 | MockRead(SYNCHRONOUS, "hello"), |
| 3321 | }; |
| 3322 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3323 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3324 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3325 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3326 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3327 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3328 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3329 | |
| 3330 | TestCompletionCallback callback1; |
| 3331 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3332 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3333 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3334 | |
| 3335 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3336 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | |
| 3338 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3339 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3340 | auto entries = log.GetEntries(); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3341 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3342 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3343 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3344 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3345 | entries, pos, |
| 3346 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3347 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3348 | |
| 3349 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3350 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3351 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3352 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3353 | EXPECT_EQ(407, response->headers->response_code()); |
| 3354 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3355 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | |
| 3357 | LoadTimingInfo load_timing_info; |
| 3358 | // CONNECT requests and responses are handled at the connect job level, so |
| 3359 | // the transaction does not yet have a connection. |
| 3360 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3361 | |
| 3362 | TestCompletionCallback callback2; |
| 3363 | |
| 3364 | rv = |
| 3365 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3367 | |
| 3368 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3369 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3370 | |
| 3371 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3372 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | |
| 3374 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3375 | EXPECT_EQ(200, response->headers->response_code()); |
| 3376 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3377 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3378 | |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 3379 | // Check that credentials were successfully cached, with the right target. |
| 3380 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 3381 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 3382 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey()); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 3383 | ASSERT_TRUE(entry); |
| 3384 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 3385 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 3386 | |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3387 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3388 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3389 | |
| 3390 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3391 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3392 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3393 | |
| 3394 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3395 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3399 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3400 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3401 | HttpRequestInfo request; |
| 3402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3403 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3404 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3405 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3406 | request.traffic_annotation = |
| 3407 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3408 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3409 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3410 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3411 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3412 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3413 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3414 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3416 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3417 | // Since we have proxy, should try to establish tunnel. |
| 3418 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3419 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3420 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3421 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3422 | }; |
| 3423 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3424 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3425 | // connection. |
| 3426 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3427 | // No credentials. |
| 3428 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3429 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3430 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3431 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3432 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3433 | MockWrite data_writes2[] = { |
| 3434 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3435 | // be issuing -- the final header line contains the credentials. |
| 3436 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3437 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3438 | "Proxy-Connection: keep-alive\r\n" |
| 3439 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3440 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3441 | MockWrite("GET / HTTP/1.1\r\n" |
| 3442 | "Host: www.example.org\r\n" |
| 3443 | "Connection: keep-alive\r\n\r\n"), |
| 3444 | }; |
| 3445 | |
| 3446 | MockRead data_reads2[] = { |
| 3447 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3448 | |
| 3449 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3450 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3451 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3452 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3453 | }; |
| 3454 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3455 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3456 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3457 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3458 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3459 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3461 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3462 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3463 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3464 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3465 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3467 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3469 | |
| 3470 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3471 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3472 | auto entries = log.GetEntries(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3473 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3474 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3475 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3476 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3477 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3478 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3479 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3480 | |
| 3481 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3482 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3483 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3484 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3485 | EXPECT_EQ(407, response->headers->response_code()); |
| 3486 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3487 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3488 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3489 | LoadTimingInfo load_timing_info; |
| 3490 | // CONNECT requests and responses are handled at the connect job level, so |
| 3491 | // the transaction does not yet have a connection. |
| 3492 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3494 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3496 | rv = trans->RestartWithAuth( |
| 3497 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3499 | |
| 3500 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3501 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3502 | |
| 3503 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3504 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3505 | |
| 3506 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3507 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3508 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3509 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3510 | |
| 3511 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3512 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3513 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3514 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3515 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3516 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3517 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3518 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3519 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3520 | } |
| 3521 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3522 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3523 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3524 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3525 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3526 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3527 | // reused. See http://crbug.com/544255. |
| 3528 | for (int i = 0; i < 2; ++i) { |
| 3529 | HttpRequestInfo request; |
| 3530 | request.method = "GET"; |
| 3531 | request.url = GURL("https://www.example.org/"); |
| 3532 | // Ensure that proxy authentication is attempted even |
| 3533 | // when the no authentication data flag is set. |
| 3534 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3535 | request.traffic_annotation = |
| 3536 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3537 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3539 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3540 | ConfiguredProxyResolutionService::CreateFixed( |
| 3541 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3542 | RecordingBoundTestNetLog log; |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3543 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3547 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3548 | // Since we have proxy, should try to establish tunnel. |
| 3549 | MockWrite data_writes1[] = { |
| 3550 | MockWrite(ASYNC, 0, |
| 3551 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3552 | "Host: www.example.org:443\r\n" |
| 3553 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3555 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3556 | // be issuing -- the final header line contains the credentials. |
| 3557 | MockWrite(ASYNC, 3, |
| 3558 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3559 | "Host: www.example.org:443\r\n" |
| 3560 | "Proxy-Connection: keep-alive\r\n" |
| 3561 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3562 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3563 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3564 | // The proxy responds to the connect with a 407, using a persistent |
| 3565 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3566 | MockRead data_reads1[] = { |
| 3567 | // No credentials. |
| 3568 | MockRead(ASYNC, 1, |
| 3569 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3570 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3571 | "Proxy-Connection: keep-alive\r\n" |
| 3572 | "Content-Length: 10\r\n\r\n"), |
| 3573 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3574 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3575 | // Wrong credentials (wrong password). |
| 3576 | MockRead(ASYNC, 4, |
| 3577 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3578 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3579 | "Proxy-Connection: keep-alive\r\n" |
| 3580 | "Content-Length: 10\r\n\r\n"), |
| 3581 | // No response body because the test stops reading here. |
| 3582 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3583 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3584 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3585 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3586 | data1.set_busy_before_sync_reads(true); |
| 3587 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3588 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3589 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3591 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3592 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3593 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3594 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3595 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3596 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3597 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3598 | ExpectLogContainsSomewhere( |
| 3599 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3600 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3601 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | ASSERT_TRUE(response); |
| 3605 | ASSERT_TRUE(response->headers); |
| 3606 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3607 | EXPECT_EQ(407, response->headers->response_code()); |
| 3608 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3609 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3610 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3611 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3612 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3613 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3614 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3615 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3616 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3617 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3619 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | ASSERT_TRUE(response); |
| 3621 | ASSERT_TRUE(response->headers); |
| 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3623 | EXPECT_EQ(407, response->headers->response_code()); |
| 3624 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3625 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3626 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3627 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3628 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3629 | // out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3630 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3631 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3635 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3636 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3637 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3638 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3639 | // reused. See http://crbug.com/544255. |
| 3640 | for (int i = 0; i < 2; ++i) { |
| 3641 | HttpRequestInfo request; |
| 3642 | request.method = "GET"; |
| 3643 | request.url = GURL("https://www.example.org/"); |
| 3644 | // Ensure that proxy authentication is attempted even |
| 3645 | // when the no authentication data flag is set. |
| 3646 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3647 | request.traffic_annotation = |
| 3648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3649 | |
| 3650 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3651 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3652 | ConfiguredProxyResolutionService::CreateFixed( |
| 3653 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3654 | RecordingBoundTestNetLog log; |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3655 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3658 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3659 | |
| 3660 | // Since we have proxy, should try to establish tunnel. |
| 3661 | MockWrite data_writes1[] = { |
| 3662 | MockWrite(ASYNC, 0, |
| 3663 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3664 | "Host: www.example.org:443\r\n" |
| 3665 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3667 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3668 | // be issuing -- the final header line contains the credentials. |
| 3669 | MockWrite(ASYNC, 3, |
| 3670 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3671 | "Host: www.example.org:443\r\n" |
| 3672 | "Proxy-Connection: keep-alive\r\n" |
| 3673 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3674 | }; |
| 3675 | |
| 3676 | // The proxy responds to the connect with a 407, using a persistent |
| 3677 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3678 | MockRead data_reads1[] = { |
| 3679 | // No credentials. |
| 3680 | MockRead(ASYNC, 1, |
| 3681 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3682 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3683 | "Content-Length: 10\r\n\r\n"), |
| 3684 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3685 | |
| 3686 | // Wrong credentials (wrong password). |
| 3687 | MockRead(ASYNC, 4, |
| 3688 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3689 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3690 | "Content-Length: 10\r\n\r\n"), |
| 3691 | // No response body because the test stops reading here. |
| 3692 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3693 | }; |
| 3694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3695 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3696 | data1.set_busy_before_sync_reads(true); |
| 3697 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3698 | |
| 3699 | TestCompletionCallback callback1; |
| 3700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3702 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3703 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3704 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3705 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3706 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3707 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3708 | ExpectLogContainsSomewhere( |
| 3709 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3710 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3711 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3713 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3714 | ASSERT_TRUE(response); |
| 3715 | ASSERT_TRUE(response->headers); |
| 3716 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3717 | EXPECT_EQ(407, response->headers->response_code()); |
| 3718 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3719 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3720 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3721 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3722 | |
| 3723 | TestCompletionCallback callback2; |
| 3724 | |
| 3725 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3726 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3727 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3728 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3730 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3731 | ASSERT_TRUE(response); |
| 3732 | ASSERT_TRUE(response->headers); |
| 3733 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3734 | EXPECT_EQ(407, response->headers->response_code()); |
| 3735 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3736 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3737 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3738 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3739 | |
| 3740 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3741 | // out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3742 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3747 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3748 | // the case the server sends extra data on the original socket, so it can't be |
| 3749 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3750 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3751 | HttpRequestInfo request; |
| 3752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3753 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3754 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3755 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3756 | request.traffic_annotation = |
| 3757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3758 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3759 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3760 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3761 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3762 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3763 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3764 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3766 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3767 | // Since we have proxy, should try to establish tunnel. |
| 3768 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3769 | MockWrite(ASYNC, 0, |
| 3770 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3771 | "Host: www.example.org:443\r\n" |
| 3772 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3773 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3774 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3775 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3776 | // extra data, so the socket cannot be reused. |
| 3777 | MockRead data_reads1[] = { |
| 3778 | // No credentials. |
| 3779 | MockRead(ASYNC, 1, |
| 3780 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3781 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3782 | "Content-Length: 10\r\n\r\n"), |
| 3783 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3784 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3785 | }; |
| 3786 | |
| 3787 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3788 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3789 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3790 | MockWrite(ASYNC, 0, |
| 3791 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3792 | "Host: www.example.org:443\r\n" |
| 3793 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3794 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3795 | |
| 3796 | MockWrite(ASYNC, 2, |
| 3797 | "GET / HTTP/1.1\r\n" |
| 3798 | "Host: www.example.org\r\n" |
| 3799 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3800 | }; |
| 3801 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3802 | MockRead data_reads2[] = { |
| 3803 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3804 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3805 | MockRead(ASYNC, 3, |
| 3806 | "HTTP/1.1 200 OK\r\n" |
| 3807 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3808 | "Content-Length: 5\r\n\r\n"), |
| 3809 | // No response body because the test stops reading here. |
| 3810 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3811 | }; |
| 3812 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3813 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3814 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3815 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3816 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3817 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3818 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3819 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3821 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3822 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3823 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3824 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3825 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3826 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3827 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3828 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3829 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3830 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3831 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3832 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3833 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3834 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3835 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3836 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3837 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3838 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3839 | ASSERT_TRUE(response); |
| 3840 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3841 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3842 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3843 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3844 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3845 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3846 | LoadTimingInfo load_timing_info; |
| 3847 | // CONNECT requests and responses are handled at the connect job level, so |
| 3848 | // the transaction does not yet have a connection. |
| 3849 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3851 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3852 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3853 | rv = |
| 3854 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3855 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3856 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3857 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3858 | EXPECT_EQ(200, response->headers->response_code()); |
| 3859 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3860 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3861 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3862 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3863 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3864 | |
| 3865 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3866 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3867 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3868 | |
| 3869 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3870 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3871 | } |
| 3872 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3873 | // Test the case a proxy closes a socket while the challenge body is being |
| 3874 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3875 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3876 | HttpRequestInfo request; |
| 3877 | request.method = "GET"; |
| 3878 | request.url = GURL("https://www.example.org/"); |
| 3879 | // Ensure that proxy authentication is attempted even |
| 3880 | // when the no authentication data flag is set. |
| 3881 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3882 | request.traffic_annotation = |
| 3883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3884 | |
| 3885 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3886 | session_deps_.proxy_resolution_service = |
| 3887 | ConfiguredProxyResolutionService::CreateFixed( |
| 3888 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3889 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3891 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3892 | |
| 3893 | // Since we have proxy, should try to establish tunnel. |
| 3894 | MockWrite data_writes1[] = { |
| 3895 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3896 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3897 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3898 | }; |
| 3899 | |
| 3900 | // The proxy responds to the connect with a 407, using a persistent |
| 3901 | // connection. |
| 3902 | MockRead data_reads1[] = { |
| 3903 | // No credentials. |
| 3904 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3905 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3906 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3907 | // Server hands up in the middle of the body. |
| 3908 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3909 | }; |
| 3910 | |
| 3911 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3912 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3913 | // be issuing -- the final header line contains the credentials. |
| 3914 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3915 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3916 | "Proxy-Connection: keep-alive\r\n" |
| 3917 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3918 | |
| 3919 | MockWrite("GET / HTTP/1.1\r\n" |
| 3920 | "Host: www.example.org\r\n" |
| 3921 | "Connection: keep-alive\r\n\r\n"), |
| 3922 | }; |
| 3923 | |
| 3924 | MockRead data_reads2[] = { |
| 3925 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3926 | |
| 3927 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3928 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3929 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3930 | MockRead(SYNCHRONOUS, "hello"), |
| 3931 | }; |
| 3932 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3933 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3935 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3936 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3937 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3938 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3939 | |
| 3940 | TestCompletionCallback callback; |
| 3941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3943 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3946 | ASSERT_TRUE(response); |
| 3947 | ASSERT_TRUE(response->headers); |
| 3948 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3949 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3950 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3952 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3953 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3955 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3956 | ASSERT_TRUE(response); |
| 3957 | ASSERT_TRUE(response->headers); |
| 3958 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3959 | EXPECT_EQ(200, response->headers->response_code()); |
| 3960 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3961 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3962 | EXPECT_EQ("hello", body); |
| 3963 | } |
| 3964 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3965 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3966 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3967 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3968 | HttpRequestInfo request; |
| 3969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3970 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3971 | request.traffic_annotation = |
| 3972 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3973 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3974 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3975 | session_deps_.proxy_resolution_service = |
| 3976 | ConfiguredProxyResolutionService::CreateFixed( |
| 3977 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3982 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3983 | // Since we have proxy, should try to establish tunnel. |
| 3984 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3985 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3986 | "Host: www.example.org:443\r\n" |
| 3987 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3988 | }; |
| 3989 | |
| 3990 | // The proxy responds to the connect with a 407. |
| 3991 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3992 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3993 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3994 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3995 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3996 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3997 | }; |
| 3998 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3999 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4002 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4003 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4004 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4006 | |
| 4007 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4008 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4010 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4011 | ASSERT_TRUE(response); |
| 4012 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4013 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4014 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4015 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4016 | |
| 4017 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4018 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4019 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4020 | |
| 4021 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4022 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4023 | } |
| 4024 | |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4025 | // Test the no-tunnel HTTP auth case where proxy and server origins and realms |
| 4026 | // are the same, but the user/passwords are different. Serves to verify |
| 4027 | // credentials are correctly separated based on HttpAuth::Target. |
| 4028 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyMatchesServerAuthNoTunnel) { |
| 4029 | HttpRequestInfo request; |
| 4030 | request.method = "GET"; |
| 4031 | request.url = GURL("http://myproxy:70/"); |
| 4032 | request.traffic_annotation = |
| 4033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4034 | |
| 4035 | // Proxy matches request URL. |
| 4036 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4037 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4038 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4039 | RecordingBoundTestNetLog log; |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4040 | session_deps_.net_log = log.bound().net_log(); |
| 4041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4042 | |
| 4043 | MockWrite data_writes[] = { |
| 4044 | // Initial request gets a proxy auth challenge. |
| 4045 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4046 | "Host: myproxy:70\r\n" |
| 4047 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4048 | // Retry with proxy auth credentials, which will result in a server auth |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4049 | // challenge. |
| 4050 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4051 | "Host: myproxy:70\r\n" |
| 4052 | "Proxy-Connection: keep-alive\r\n" |
| 4053 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4054 | // Retry with proxy and server auth credentials, which gets a response. |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4055 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4056 | "Host: myproxy:70\r\n" |
| 4057 | "Proxy-Connection: keep-alive\r\n" |
| 4058 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4059 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4060 | // A second request should preemptively send the correct proxy and server |
| 4061 | // auth headers. |
| 4062 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4063 | "Host: myproxy:70\r\n" |
| 4064 | "Proxy-Connection: keep-alive\r\n" |
| 4065 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4066 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4067 | }; |
| 4068 | |
| 4069 | MockRead data_reads[] = { |
| 4070 | // Proxy auth challenge. |
| 4071 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4072 | "Proxy-Connection: keep-alive\r\n" |
| 4073 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4074 | "Content-Length: 0\r\n\r\n"), |
| 4075 | // Server auth challenge. |
| 4076 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4077 | "Proxy-Connection: keep-alive\r\n" |
| 4078 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4079 | "Content-Length: 0\r\n\r\n"), |
| 4080 | // Response. |
| 4081 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4082 | "Proxy-Connection: keep-alive\r\n" |
| 4083 | "Content-Length: 5\r\n\r\n" |
| 4084 | "hello"), |
| 4085 | // Response to second request. |
| 4086 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4087 | "Proxy-Connection: keep-alive\r\n" |
| 4088 | "Content-Length: 2\r\n\r\n" |
| 4089 | "hi"), |
| 4090 | }; |
| 4091 | |
| 4092 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4093 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4094 | |
| 4095 | TestCompletionCallback callback; |
| 4096 | |
| 4097 | auto trans = |
| 4098 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4099 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4100 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4102 | ASSERT_TRUE(response); |
| 4103 | ASSERT_TRUE(response->headers); |
| 4104 | EXPECT_EQ(407, response->headers->response_code()); |
| 4105 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
| 4106 | |
| 4107 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4108 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4109 | response = trans->GetResponseInfo(); |
| 4110 | ASSERT_TRUE(response); |
| 4111 | EXPECT_EQ(401, response->headers->response_code()); |
| 4112 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4113 | EXPECT_EQ("http://myproxy:70", |
| 4114 | response->auth_challenge->challenger.Serialize()); |
| 4115 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4116 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4117 | |
| 4118 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4119 | callback.callback()); |
| 4120 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4121 | response = trans->GetResponseInfo(); |
| 4122 | ASSERT_TRUE(response); |
| 4123 | EXPECT_EQ(200, response->headers->response_code()); |
| 4124 | // The password prompt info should not be set. |
| 4125 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4126 | |
| 4127 | std::string response_data; |
| 4128 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4129 | EXPECT_EQ("hello", response_data); |
| 4130 | |
| 4131 | // Check that the credentials were cached correctly. |
| 4132 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4133 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4134 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey()); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4135 | ASSERT_TRUE(entry); |
| 4136 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4137 | ASSERT_EQ(kBar, entry->credentials().password()); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4138 | entry = session->http_auth_cache()->Lookup( |
| 4139 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4140 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey()); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4141 | ASSERT_TRUE(entry); |
| 4142 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4143 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4144 | |
| 4145 | // Make another request, which should automatically send the correct proxy and |
| 4146 | // server auth credentials and get another response. |
| 4147 | trans = |
| 4148 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4149 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4150 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4151 | response = trans->GetResponseInfo(); |
| 4152 | ASSERT_TRUE(response); |
| 4153 | EXPECT_EQ(200, response->headers->response_code()); |
| 4154 | // The password prompt info should not be set. |
| 4155 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4156 | |
| 4157 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4158 | EXPECT_EQ("hi", response_data); |
| 4159 | |
| 4160 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4161 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4162 | } |
| 4163 | |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4164 | // Test the no-tunnel HTTP auth case where proxy and server origins and realms |
| 4165 | // are the same, but the user/passwords are different, and with different |
| 4166 | // NetworkIsolationKeys. Sends one request with a NIK, response to both proxy |
| 4167 | // and auth challenges, sends another request with another NIK, expecting only |
| 4168 | // the proxy credentials to be cached, and thus sees only a server auth |
| 4169 | // challenge. Then sends a request with the original NIK, expecting cached proxy |
| 4170 | // and auth credentials that match the ones used in the first request. |
| 4171 | // |
| 4172 | // Serves to verify credentials are correctly separated based on |
| 4173 | // HttpAuth::Target and NetworkIsolationKeys, but NetworkIsolationKey only |
| 4174 | // affects server credentials, not proxy credentials. |
| 4175 | TEST_F(HttpNetworkTransactionTest, |
| 4176 | BasicAuthProxyMatchesServerAuthWithNetworkIsolationKeyNoTunnel) { |
| 4177 | const url::Origin kOrigin1 = url::Origin::Create(GURL("https://foo.test/")); |
| 4178 | const net::NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 4179 | const url::Origin kOrigin2 = url::Origin::Create(GURL("https://bar.test/")); |
| 4180 | const net::NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
| 4181 | |
| 4182 | // This test would need to use a single socket without this option enabled. |
| 4183 | // Best to use this option when it would affect a test, as it will eventually |
| 4184 | // become the default behavior. |
| 4185 | base::test::ScopedFeatureList feature_list; |
| 4186 | feature_list.InitAndEnableFeature( |
| 4187 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 4188 | |
| 4189 | // Proxy matches request URL. |
| 4190 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4191 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4192 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4193 | RecordingBoundTestNetLog log; |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4194 | session_deps_.net_log = log.bound().net_log(); |
| 4195 | session_deps_.key_auth_cache_server_entries_by_network_isolation_key = true; |
| 4196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4197 | |
| 4198 | MockWrite data_writes[] = { |
| 4199 | // Initial request gets a proxy auth challenge. |
| 4200 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4201 | "Host: myproxy:70\r\n" |
| 4202 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4203 | // Retry with proxy auth credentials, which will result in a server auth |
| 4204 | // challenge. |
| 4205 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4206 | "Host: myproxy:70\r\n" |
| 4207 | "Proxy-Connection: keep-alive\r\n" |
| 4208 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4209 | // Retry with proxy and server auth credentials, which gets a response. |
| 4210 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4211 | "Host: myproxy:70\r\n" |
| 4212 | "Proxy-Connection: keep-alive\r\n" |
| 4213 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4214 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4215 | // Another request to the same server and using the same NIK should |
| 4216 | // preemptively send the correct cached proxy and server |
| 4217 | // auth headers. |
| 4218 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4219 | "Host: myproxy:70\r\n" |
| 4220 | "Proxy-Connection: keep-alive\r\n" |
| 4221 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4222 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4223 | }; |
| 4224 | |
| 4225 | MockRead data_reads[] = { |
| 4226 | // Proxy auth challenge. |
| 4227 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4228 | "Proxy-Connection: keep-alive\r\n" |
| 4229 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4230 | "Content-Length: 0\r\n\r\n"), |
| 4231 | // Server auth challenge. |
| 4232 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4233 | "Proxy-Connection: keep-alive\r\n" |
| 4234 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4235 | "Content-Length: 0\r\n\r\n"), |
| 4236 | // Response. |
| 4237 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4238 | "Proxy-Connection: keep-alive\r\n" |
| 4239 | "Content-Length: 5\r\n\r\n" |
| 4240 | "hello"), |
| 4241 | // Response to second request. |
| 4242 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4243 | "Proxy-Connection: keep-alive\r\n" |
| 4244 | "Content-Length: 2\r\n\r\n" |
| 4245 | "hi"), |
| 4246 | }; |
| 4247 | |
| 4248 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4250 | |
| 4251 | MockWrite data_writes2[] = { |
| 4252 | // Initial request using a different NetworkIsolationKey includes the |
| 4253 | // cached proxy credentials, but not server credentials. |
| 4254 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4255 | "Host: myproxy:70\r\n" |
| 4256 | "Proxy-Connection: keep-alive\r\n" |
| 4257 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4258 | // Retry with proxy and new server auth credentials, which gets a |
| 4259 | // response. |
| 4260 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4261 | "Host: myproxy:70\r\n" |
| 4262 | "Proxy-Connection: keep-alive\r\n" |
| 4263 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4264 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 4265 | }; |
| 4266 | |
| 4267 | MockRead data_reads2[] = { |
| 4268 | // Server auth challenge. |
| 4269 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4270 | "Proxy-Connection: keep-alive\r\n" |
| 4271 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4272 | "Content-Length: 0\r\n\r\n"), |
| 4273 | // Response. |
| 4274 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4275 | "Proxy-Connection: keep-alive\r\n" |
| 4276 | "Content-Length: 9\r\n\r\n" |
| 4277 | "greetings"), |
| 4278 | }; |
| 4279 | |
| 4280 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 4281 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4282 | |
| 4283 | TestCompletionCallback callback; |
| 4284 | |
| 4285 | HttpRequestInfo request; |
| 4286 | request.method = "GET"; |
| 4287 | request.url = GURL("http://myproxy:70/"); |
| 4288 | request.traffic_annotation = |
| 4289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4290 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4291 | |
| 4292 | auto trans = |
| 4293 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4294 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4295 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4296 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4297 | ASSERT_TRUE(response); |
| 4298 | ASSERT_TRUE(response->headers); |
| 4299 | EXPECT_EQ(407, response->headers->response_code()); |
| 4300 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
| 4301 | |
| 4302 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4303 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4304 | response = trans->GetResponseInfo(); |
| 4305 | ASSERT_TRUE(response); |
| 4306 | EXPECT_EQ(401, response->headers->response_code()); |
| 4307 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4308 | EXPECT_EQ("http://myproxy:70", |
| 4309 | response->auth_challenge->challenger.Serialize()); |
| 4310 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4311 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4312 | |
| 4313 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4314 | callback.callback()); |
| 4315 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4316 | response = trans->GetResponseInfo(); |
| 4317 | ASSERT_TRUE(response); |
| 4318 | EXPECT_EQ(200, response->headers->response_code()); |
| 4319 | // The password prompt info should not be set. |
| 4320 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4321 | std::string response_data; |
| 4322 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4323 | EXPECT_EQ("hello", response_data); |
| 4324 | |
| 4325 | // Check that the proxy credentials were cached correctly. The should be |
| 4326 | // accessible with any NetworkIsolationKey. |
| 4327 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4328 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4329 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4330 | ASSERT_TRUE(entry); |
| 4331 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4332 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4333 | EXPECT_EQ(entry, |
| 4334 | session->http_auth_cache()->Lookup( |
| 4335 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4336 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4337 | |
| 4338 | // Check that the server credentials were cached correctly. The should be |
| 4339 | // accessible with only kNetworkIsolationKey1. |
| 4340 | entry = session->http_auth_cache()->Lookup( |
| 4341 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4342 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4343 | ASSERT_TRUE(entry); |
| 4344 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4345 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4346 | // Looking up the server entry with another NetworkIsolationKey should fail. |
| 4347 | EXPECT_FALSE(session->http_auth_cache()->Lookup( |
| 4348 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4349 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4350 | |
| 4351 | // Make another request with a different NetworkIsolationKey. It should use |
| 4352 | // another socket, reuse the cached proxy credentials, but result in a server |
| 4353 | // auth challenge. |
| 4354 | request.network_isolation_key = kNetworkIsolationKey2; |
| 4355 | trans = |
| 4356 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4357 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4358 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4359 | response = trans->GetResponseInfo(); |
| 4360 | ASSERT_TRUE(response); |
| 4361 | EXPECT_EQ(401, response->headers->response_code()); |
| 4362 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4363 | EXPECT_EQ("http://myproxy:70", |
| 4364 | response->auth_challenge->challenger.Serialize()); |
| 4365 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4366 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4367 | |
| 4368 | rv = trans->RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 4369 | callback.callback()); |
| 4370 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4371 | response = trans->GetResponseInfo(); |
| 4372 | ASSERT_TRUE(response); |
| 4373 | EXPECT_EQ(200, response->headers->response_code()); |
| 4374 | // The password prompt info should not be set. |
| 4375 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4376 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4377 | EXPECT_EQ("greetings", response_data); |
| 4378 | |
| 4379 | // Check that the proxy credentials are still cached. |
| 4380 | entry = session->http_auth_cache()->Lookup( |
| 4381 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4382 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4383 | ASSERT_TRUE(entry); |
| 4384 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4385 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4386 | EXPECT_EQ(entry, |
| 4387 | session->http_auth_cache()->Lookup( |
| 4388 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4389 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4390 | |
| 4391 | // Check that the correct server credentials are cached for each |
| 4392 | // NetworkIsolationKey. |
| 4393 | entry = session->http_auth_cache()->Lookup( |
| 4394 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4395 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4396 | ASSERT_TRUE(entry); |
| 4397 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4398 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4399 | entry = session->http_auth_cache()->Lookup( |
| 4400 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4401 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2); |
| 4402 | ASSERT_TRUE(entry); |
| 4403 | ASSERT_EQ(kFoo3, entry->credentials().username()); |
| 4404 | ASSERT_EQ(kBar3, entry->credentials().password()); |
| 4405 | |
| 4406 | // Make a request with the original NetworkIsolationKey. It should reuse the |
| 4407 | // first socket, and the proxy credentials sent on the first socket. |
| 4408 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4409 | trans = |
| 4410 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4411 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4412 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4413 | response = trans->GetResponseInfo(); |
| 4414 | ASSERT_TRUE(response); |
| 4415 | EXPECT_EQ(200, response->headers->response_code()); |
| 4416 | // The password prompt info should not be set. |
| 4417 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4418 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4419 | EXPECT_EQ("hi", response_data); |
| 4420 | |
| 4421 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4422 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | // Much like the test above, but uses tunnelled connections. |
| 4426 | TEST_F(HttpNetworkTransactionTest, |
| 4427 | BasicAuthProxyMatchesServerAuthWithNetworkIsolationKeyWithTunnel) { |
| 4428 | const url::Origin kOrigin1 = url::Origin::Create(GURL("https://foo.test/")); |
| 4429 | const net::NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 4430 | const url::Origin kOrigin2 = url::Origin::Create(GURL("https://bar.test/")); |
| 4431 | const net::NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
| 4432 | |
| 4433 | // This test would need to use a single socket without this option enabled. |
| 4434 | // Best to use this option when it would affect a test, as it will eventually |
| 4435 | // become the default behavior. |
| 4436 | base::test::ScopedFeatureList feature_list; |
| 4437 | feature_list.InitAndEnableFeature( |
| 4438 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 4439 | |
| 4440 | // Proxy matches request URL. |
| 4441 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4442 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4443 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4444 | RecordingBoundTestNetLog log; |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4445 | session_deps_.net_log = log.bound().net_log(); |
| 4446 | session_deps_.key_auth_cache_server_entries_by_network_isolation_key = true; |
| 4447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4448 | |
| 4449 | MockWrite data_writes[] = { |
| 4450 | // Initial tunnel request gets a proxy auth challenge. |
| 4451 | MockWrite("CONNECT myproxy:70 HTTP/1.1\r\n" |
| 4452 | "Host: myproxy:70\r\n" |
| 4453 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4454 | // Retry with proxy auth credentials, which will result in establishing a |
| 4455 | // tunnel. |
| 4456 | MockWrite("CONNECT myproxy:70 HTTP/1.1\r\n" |
| 4457 | "Host: myproxy:70\r\n" |
| 4458 | "Proxy-Connection: keep-alive\r\n" |
| 4459 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4460 | // Request over the tunnel, which gets a server auth challenge. |
| 4461 | MockWrite("GET / HTTP/1.1\r\n" |
| 4462 | "Host: myproxy:70\r\n" |
| 4463 | "Connection: keep-alive\r\n\r\n"), |
| 4464 | // Retry with server auth credentials, which gets a response. |
| 4465 | MockWrite("GET / HTTP/1.1\r\n" |
| 4466 | "Host: myproxy:70\r\n" |
| 4467 | "Connection: keep-alive\r\n" |
| 4468 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4469 | // Another request to the same server and using the same NIK should |
| 4470 | // preemptively send the correct cached server |
| 4471 | // auth header. Since a tunnel was already established, the proxy headers |
| 4472 | // won't be sent again except when establishing another tunnel. |
| 4473 | MockWrite("GET / HTTP/1.1\r\n" |
| 4474 | "Host: myproxy:70\r\n" |
| 4475 | "Connection: keep-alive\r\n" |
| 4476 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4477 | }; |
| 4478 | |
| 4479 | MockRead data_reads[] = { |
| 4480 | // Proxy auth challenge. |
| 4481 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4482 | "Proxy-Connection: keep-alive\r\n" |
| 4483 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4484 | "Content-Length: 0\r\n\r\n"), |
| 4485 | // Tunnel success |
| 4486 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4487 | // Server auth challenge. |
| 4488 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4489 | "Connection: keep-alive\r\n" |
| 4490 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4491 | "Content-Length: 0\r\n\r\n"), |
| 4492 | // Response. |
| 4493 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4494 | "Connection: keep-alive\r\n" |
| 4495 | "Content-Length: 5\r\n\r\n" |
| 4496 | "hello"), |
| 4497 | // Response to second request. |
| 4498 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4499 | "Connection: keep-alive\r\n" |
| 4500 | "Content-Length: 2\r\n\r\n" |
| 4501 | "hi"), |
| 4502 | }; |
| 4503 | |
| 4504 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4505 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4506 | // One for the proxy connection, one of the server connection. |
| 4507 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4508 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4509 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 4510 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 4511 | |
| 4512 | MockWrite data_writes2[] = { |
| 4513 | // Initial request using a different NetworkIsolationKey includes the |
| 4514 | // cached proxy credentials when establishing a tunnel. |
| 4515 | MockWrite("CONNECT myproxy:70 HTTP/1.1\r\n" |
| 4516 | "Host: myproxy:70\r\n" |
| 4517 | "Proxy-Connection: keep-alive\r\n" |
| 4518 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4519 | // Request over the tunnel, which gets a server auth challenge. Cached |
| 4520 | // credentials cannot be used, since the NIK is different. |
| 4521 | MockWrite("GET / HTTP/1.1\r\n" |
| 4522 | "Host: myproxy:70\r\n" |
| 4523 | "Connection: keep-alive\r\n\r\n"), |
| 4524 | // Retry with server auth credentials, which gets a response. |
| 4525 | MockWrite("GET / HTTP/1.1\r\n" |
| 4526 | "Host: myproxy:70\r\n" |
| 4527 | "Connection: keep-alive\r\n" |
| 4528 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 4529 | }; |
| 4530 | |
| 4531 | MockRead data_reads2[] = { |
| 4532 | // Tunnel success |
| 4533 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4534 | // Server auth challenge. |
| 4535 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4536 | "Connection: keep-alive\r\n" |
| 4537 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4538 | "Content-Length: 0\r\n\r\n"), |
| 4539 | // Response. |
| 4540 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4541 | "Connection: keep-alive\r\n" |
| 4542 | "Content-Length: 9\r\n\r\n" |
| 4543 | "greetings"), |
| 4544 | }; |
| 4545 | |
| 4546 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 4547 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4548 | // One for the proxy connection, one of the server connection. |
| 4549 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 4550 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 4551 | SSLSocketDataProvider ssl4(ASYNC, OK); |
| 4552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl4); |
| 4553 | |
| 4554 | TestCompletionCallback callback; |
| 4555 | |
| 4556 | HttpRequestInfo request; |
| 4557 | request.method = "GET"; |
| 4558 | request.url = GURL("https://myproxy:70/"); |
| 4559 | request.traffic_annotation = |
| 4560 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4561 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4562 | |
| 4563 | auto trans = |
| 4564 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4565 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4566 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4567 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4568 | ASSERT_TRUE(response); |
| 4569 | ASSERT_TRUE(response->headers); |
| 4570 | EXPECT_EQ(407, response->headers->response_code()); |
| 4571 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
| 4572 | |
| 4573 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4574 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4575 | response = trans->GetResponseInfo(); |
| 4576 | ASSERT_TRUE(response); |
| 4577 | EXPECT_EQ(401, response->headers->response_code()); |
| 4578 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4579 | EXPECT_EQ("https://myproxy:70", |
| 4580 | response->auth_challenge->challenger.Serialize()); |
| 4581 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4582 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4583 | |
| 4584 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4585 | callback.callback()); |
| 4586 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4587 | response = trans->GetResponseInfo(); |
| 4588 | ASSERT_TRUE(response); |
| 4589 | EXPECT_EQ(200, response->headers->response_code()); |
| 4590 | // The password prompt info should not be set. |
| 4591 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4592 | std::string response_data; |
| 4593 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4594 | EXPECT_EQ("hello", response_data); |
| 4595 | |
| 4596 | // Check that the proxy credentials were cached correctly. The should be |
| 4597 | // accessible with any NetworkIsolationKey. |
| 4598 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4599 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4600 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4601 | ASSERT_TRUE(entry); |
| 4602 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4603 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4604 | EXPECT_EQ(entry, |
| 4605 | session->http_auth_cache()->Lookup( |
| 4606 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4607 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4608 | |
| 4609 | // Check that the server credentials were cached correctly. The should be |
| 4610 | // accessible with only kNetworkIsolationKey1. |
| 4611 | entry = session->http_auth_cache()->Lookup( |
| 4612 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4613 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4614 | ASSERT_TRUE(entry); |
| 4615 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4616 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4617 | // Looking up the server entry with another NetworkIsolationKey should fail. |
| 4618 | EXPECT_FALSE(session->http_auth_cache()->Lookup( |
| 4619 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4620 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4621 | |
| 4622 | // Make another request with a different NetworkIsolationKey. It should use |
| 4623 | // another socket, reuse the cached proxy credentials, but result in a server |
| 4624 | // auth challenge. |
| 4625 | request.network_isolation_key = kNetworkIsolationKey2; |
| 4626 | trans = |
| 4627 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4628 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4629 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4630 | response = trans->GetResponseInfo(); |
| 4631 | ASSERT_TRUE(response); |
| 4632 | EXPECT_EQ(401, response->headers->response_code()); |
| 4633 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4634 | EXPECT_EQ("https://myproxy:70", |
| 4635 | response->auth_challenge->challenger.Serialize()); |
| 4636 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4637 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4638 | |
| 4639 | rv = trans->RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 4640 | callback.callback()); |
| 4641 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4642 | response = trans->GetResponseInfo(); |
| 4643 | ASSERT_TRUE(response); |
| 4644 | EXPECT_EQ(200, response->headers->response_code()); |
| 4645 | // The password prompt info should not be set. |
| 4646 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4647 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4648 | EXPECT_EQ("greetings", response_data); |
| 4649 | |
| 4650 | // Check that the proxy credentials are still cached. |
| 4651 | entry = session->http_auth_cache()->Lookup( |
| 4652 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4653 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4654 | ASSERT_TRUE(entry); |
| 4655 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4656 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4657 | EXPECT_EQ(entry, |
| 4658 | session->http_auth_cache()->Lookup( |
| 4659 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4660 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4661 | |
| 4662 | // Check that the correct server credentials are cached for each |
| 4663 | // NetworkIsolationKey. |
| 4664 | entry = session->http_auth_cache()->Lookup( |
| 4665 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4666 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4667 | ASSERT_TRUE(entry); |
| 4668 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4669 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4670 | entry = session->http_auth_cache()->Lookup( |
| 4671 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4672 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2); |
| 4673 | ASSERT_TRUE(entry); |
| 4674 | ASSERT_EQ(kFoo3, entry->credentials().username()); |
| 4675 | ASSERT_EQ(kBar3, entry->credentials().password()); |
| 4676 | |
| 4677 | // Make a request with the original NetworkIsolationKey. It should reuse the |
| 4678 | // first socket, and the proxy credentials sent on the first socket. |
| 4679 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4680 | trans = |
| 4681 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4682 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4683 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4684 | response = trans->GetResponseInfo(); |
| 4685 | ASSERT_TRUE(response); |
| 4686 | EXPECT_EQ(200, response->headers->response_code()); |
| 4687 | // The password prompt info should not be set. |
| 4688 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4689 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4690 | EXPECT_EQ("hi", response_data); |
| 4691 | |
| 4692 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4693 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4694 | } |
| 4695 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4696 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4697 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4698 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4699 | HttpRequestInfo request; |
| 4700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4701 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4702 | request.traffic_annotation = |
| 4703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4704 | |
| 4705 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4706 | session_deps_.proxy_resolution_service = |
| 4707 | ConfiguredProxyResolutionService::CreateFixed( |
| 4708 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4709 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4710 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4713 | |
| 4714 | // Since we have proxy, should try to establish tunnel. |
| 4715 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4716 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4717 | "Host: www.example.org:443\r\n" |
| 4718 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4719 | }; |
| 4720 | |
| 4721 | // The proxy responds to the connect with a 407. |
| 4722 | MockRead data_reads[] = { |
| 4723 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4724 | MockRead("X-Foo: bar\r\n"), |
| 4725 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4726 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4727 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4728 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4729 | }; |
| 4730 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4731 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4733 | |
| 4734 | TestCompletionCallback callback; |
| 4735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4736 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4738 | |
| 4739 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4740 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4743 | ASSERT_TRUE(response); |
| 4744 | ASSERT_TRUE(response->headers); |
| 4745 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4746 | EXPECT_EQ(407, response->headers->response_code()); |
| 4747 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4748 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4749 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4750 | |
| 4751 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4752 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4753 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4754 | |
| 4755 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4756 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4757 | } |
| 4758 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4759 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4760 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4761 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4762 | HttpRequestInfo request; |
| 4763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4764 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4765 | request.traffic_annotation = |
| 4766 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4767 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4768 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4771 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4772 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4773 | MockWrite( |
| 4774 | "GET / HTTP/1.1\r\n" |
| 4775 | "Host: www.example.org\r\n" |
| 4776 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4777 | }; |
| 4778 | |
| 4779 | MockRead data_reads1[] = { |
| 4780 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4781 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4782 | // Large content-length -- won't matter, as connection will be reset. |
| 4783 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4784 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4785 | }; |
| 4786 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4787 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4788 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4790 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4794 | |
| 4795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4796 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4797 | } |
| 4798 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4799 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4800 | // through a non-authenticating proxy. The request should fail with |
| 4801 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4802 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4803 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4804 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4805 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4806 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4807 | HttpRequestInfo request; |
| 4808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4809 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4810 | request.traffic_annotation = |
| 4811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4812 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4813 | session_deps_.proxy_resolution_service = |
| 4814 | ConfiguredProxyResolutionService::CreateFixed( |
| 4815 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4816 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4817 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4818 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4819 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4820 | // Since we have proxy, should try to establish tunnel. |
| 4821 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4822 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4823 | "Host: www.example.org:443\r\n" |
| 4824 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4825 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4826 | MockWrite("GET / HTTP/1.1\r\n" |
| 4827 | "Host: www.example.org\r\n" |
| 4828 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4829 | }; |
| 4830 | |
| 4831 | MockRead data_reads1[] = { |
| 4832 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4833 | |
| 4834 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4835 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4836 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4837 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4838 | }; |
| 4839 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4840 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4841 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4842 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4845 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4848 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4849 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4851 | |
| 4852 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4853 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 4854 | auto entries = log.GetEntries(); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4855 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4856 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4857 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4858 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4859 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4860 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4861 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4862 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4863 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4864 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4865 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4866 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4867 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4868 | HttpRequestInfo request; |
| 4869 | request.method = "GET"; |
| 4870 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4871 | request.traffic_annotation = |
| 4872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4873 | |
| 4874 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4875 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4876 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4877 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4878 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4879 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4880 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4881 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4882 | mock_handler->set_allows_default_credentials(true); |
| 4883 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4884 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4885 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4886 | |
| 4887 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 4888 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4889 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4890 | |
| 4891 | // Since we have proxy, should try to establish tunnel. |
| 4892 | MockWrite data_writes1[] = { |
| 4893 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4894 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4895 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4896 | }; |
| 4897 | |
| 4898 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4899 | // connection. |
| 4900 | MockRead data_reads1[] = { |
| 4901 | // No credentials. |
| 4902 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4903 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4904 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4905 | }; |
| 4906 | |
| 4907 | // Since the first connection couldn't be reused, need to establish another |
| 4908 | // once given credentials. |
| 4909 | MockWrite data_writes2[] = { |
| 4910 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4911 | // be issuing -- the final header line contains the credentials. |
| 4912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4913 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4914 | "Proxy-Connection: keep-alive\r\n" |
| 4915 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4916 | |
| 4917 | MockWrite("GET / HTTP/1.1\r\n" |
| 4918 | "Host: www.example.org\r\n" |
| 4919 | "Connection: keep-alive\r\n\r\n"), |
| 4920 | }; |
| 4921 | |
| 4922 | MockRead data_reads2[] = { |
| 4923 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4924 | |
| 4925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4926 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4927 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4928 | MockRead(SYNCHRONOUS, "hello"), |
| 4929 | }; |
| 4930 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4931 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4933 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4935 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4937 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4938 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4939 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4940 | |
| 4941 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4942 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4943 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4944 | |
| 4945 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4946 | ASSERT_TRUE(response); |
| 4947 | ASSERT_TRUE(response->headers); |
| 4948 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4949 | EXPECT_EQ(407, response->headers->response_code()); |
| 4950 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4951 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4952 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4953 | |
| 4954 | LoadTimingInfo load_timing_info; |
| 4955 | // CONNECT requests and responses are handled at the connect job level, so |
| 4956 | // the transaction does not yet have a connection. |
| 4957 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4958 | |
| 4959 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4960 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4961 | response = trans->GetResponseInfo(); |
| 4962 | ASSERT_TRUE(response); |
| 4963 | ASSERT_TRUE(response->headers); |
| 4964 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4965 | EXPECT_EQ(200, response->headers->response_code()); |
| 4966 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4967 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4968 | |
| 4969 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4970 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4971 | |
| 4972 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4973 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4974 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4975 | |
| 4976 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4977 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4981 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4982 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4983 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4984 | HttpRequestInfo request; |
| 4985 | request.method = "GET"; |
| 4986 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4987 | request.traffic_annotation = |
| 4988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4989 | |
| 4990 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4991 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4992 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4993 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4994 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4995 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4996 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4997 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4998 | mock_handler->set_allows_default_credentials(true); |
| 4999 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5000 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5001 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5002 | |
| 5003 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5004 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5005 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5006 | |
| 5007 | // Should try to establish tunnel. |
| 5008 | MockWrite data_writes1[] = { |
| 5009 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5010 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5011 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5012 | |
| 5013 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5014 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5015 | "Proxy-Connection: keep-alive\r\n" |
| 5016 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5017 | }; |
| 5018 | |
| 5019 | // The proxy responds to the connect with a 407, using a non-persistent |
| 5020 | // connection. |
| 5021 | MockRead data_reads1[] = { |
| 5022 | // No credentials. |
| 5023 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5024 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 5025 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5026 | }; |
| 5027 | |
| 5028 | // Since the first connection was closed, need to establish another once given |
| 5029 | // credentials. |
| 5030 | MockWrite data_writes2[] = { |
| 5031 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5032 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5033 | "Proxy-Connection: keep-alive\r\n" |
| 5034 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5035 | |
| 5036 | MockWrite("GET / HTTP/1.1\r\n" |
| 5037 | "Host: www.example.org\r\n" |
| 5038 | "Connection: keep-alive\r\n\r\n"), |
| 5039 | }; |
| 5040 | |
| 5041 | MockRead data_reads2[] = { |
| 5042 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 5043 | |
| 5044 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5045 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5046 | MockRead("Content-Length: 5\r\n\r\n"), |
| 5047 | MockRead(SYNCHRONOUS, "hello"), |
| 5048 | }; |
| 5049 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5050 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5051 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5052 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5053 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5054 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5056 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5057 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5058 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5059 | |
| 5060 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5061 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5062 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5063 | |
| 5064 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5065 | ASSERT_TRUE(response); |
| 5066 | ASSERT_TRUE(response->headers); |
| 5067 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5068 | EXPECT_EQ(407, response->headers->response_code()); |
| 5069 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5070 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5071 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5072 | |
| 5073 | LoadTimingInfo load_timing_info; |
| 5074 | // CONNECT requests and responses are handled at the connect job level, so |
| 5075 | // the transaction does not yet have a connection. |
| 5076 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5077 | |
| 5078 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5079 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5080 | |
| 5081 | response = trans->GetResponseInfo(); |
| 5082 | ASSERT_TRUE(response); |
| 5083 | ASSERT_TRUE(response->headers); |
| 5084 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5085 | EXPECT_EQ(200, response->headers->response_code()); |
| 5086 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 5087 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5088 | |
| 5089 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5090 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5091 | |
| 5092 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5093 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5094 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5095 | |
| 5096 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5097 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 5101 | // that hangs up when credentials are initially sent, and hangs up again when |
| 5102 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5103 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5104 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 5105 | HttpRequestInfo request; |
| 5106 | request.method = "GET"; |
| 5107 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5108 | request.traffic_annotation = |
| 5109 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5110 | |
| 5111 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5112 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5113 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5114 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5115 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5116 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5117 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5118 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5119 | mock_handler->set_allows_default_credentials(true); |
| 5120 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5121 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5122 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5123 | |
| 5124 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5125 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5126 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5127 | |
| 5128 | // Should try to establish tunnel. |
| 5129 | MockWrite data_writes1[] = { |
| 5130 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5131 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5132 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5133 | |
| 5134 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5135 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5136 | "Proxy-Connection: keep-alive\r\n" |
| 5137 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5138 | }; |
| 5139 | |
| 5140 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 5141 | // second request is sent. |
| 5142 | MockRead data_reads1[] = { |
| 5143 | // No credentials. |
| 5144 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5145 | MockRead("Content-Length: 0\r\n"), |
| 5146 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5147 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 5148 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5149 | }; |
| 5150 | |
| 5151 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 5152 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 5153 | // request. |
| 5154 | MockWrite data_writes2[] = { |
| 5155 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5156 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5157 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5158 | }; |
| 5159 | |
| 5160 | // The proxy, having had more than enough of us, just hangs up. |
| 5161 | MockRead data_reads2[] = { |
| 5162 | // No credentials. |
| 5163 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5164 | }; |
| 5165 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5166 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5167 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5168 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5169 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5170 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5171 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5172 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5173 | |
| 5174 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5175 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5176 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5177 | |
| 5178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5179 | ASSERT_TRUE(response); |
| 5180 | ASSERT_TRUE(response->headers); |
| 5181 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5182 | EXPECT_EQ(407, response->headers->response_code()); |
| 5183 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5184 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5185 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5186 | |
| 5187 | LoadTimingInfo load_timing_info; |
| 5188 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5189 | |
| 5190 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5191 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5192 | |
| 5193 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5194 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5195 | } |
| 5196 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5197 | // This test exercises an odd edge case where the proxy closes the connection |
| 5198 | // after the authentication handshake is complete. Presumably this technique is |
| 5199 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 5200 | // succeeds, but the user is not authorized to connect to the destination |
| 5201 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 5202 | // site. |
| 5203 | TEST_F(HttpNetworkTransactionTest, |
| 5204 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 5205 | HttpRequestInfo request; |
| 5206 | request.method = "GET"; |
| 5207 | request.url = GURL("https://www.example.org/"); |
| 5208 | request.traffic_annotation = |
| 5209 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5210 | |
| 5211 | // Configure against proxy server "myproxy:70". |
| 5212 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5213 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5214 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5215 | |
| 5216 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 5217 | auth_handler_factory->set_do_init_from_challenge(true); |
| 5218 | |
| 5219 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 5220 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 5221 | // was a real network error. |
| 5222 | // |
| 5223 | // The handlers support both default and explicit credentials. The retry |
| 5224 | // mentioned above should be able to reuse the default identity. Thus there |
| 5225 | // should never be a need to prompt for explicit credentials. |
| 5226 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 5227 | mock_handler->set_allows_default_credentials(true); |
| 5228 | mock_handler->set_allows_explicit_credentials(true); |
| 5229 | mock_handler->set_connection_based(true); |
| 5230 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5231 | HttpAuth::AUTH_PROXY); |
| 5232 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 5233 | mock_handler->set_allows_default_credentials(true); |
| 5234 | mock_handler->set_allows_explicit_credentials(true); |
| 5235 | mock_handler->set_connection_based(true); |
| 5236 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5237 | HttpAuth::AUTH_PROXY); |
| 5238 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 5239 | |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5240 | session_deps_.net_log = NetLog::Get(); |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5241 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5242 | |
| 5243 | // Data for both sockets. |
| 5244 | // |
| 5245 | // Writes are for the tunnel establishment attempts and the |
| 5246 | // authentication handshake. |
| 5247 | MockWrite data_writes1[] = { |
| 5248 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5249 | "Host: www.example.org:443\r\n" |
| 5250 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5251 | |
| 5252 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5253 | "Host: www.example.org:443\r\n" |
| 5254 | "Proxy-Connection: keep-alive\r\n" |
| 5255 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5256 | |
| 5257 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5258 | "Host: www.example.org:443\r\n" |
| 5259 | "Proxy-Connection: keep-alive\r\n" |
| 5260 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5261 | }; |
| 5262 | |
| 5263 | // The server side of the authentication handshake. Note that the response to |
| 5264 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 5265 | MockRead data_reads1[] = { |
| 5266 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5267 | MockRead("Content-Length: 0\r\n"), |
| 5268 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5269 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 5270 | |
| 5271 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5272 | MockRead("Content-Length: 0\r\n"), |
| 5273 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5274 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 5275 | |
| 5276 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5277 | }; |
| 5278 | |
| 5279 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 5280 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5281 | |
| 5282 | // The second socket is for the reconnection attempt. Data is identical to the |
| 5283 | // first attempt. |
| 5284 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 5285 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5286 | |
| 5287 | auto trans = |
| 5288 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 5289 | |
| 5290 | TestCompletionCallback callback; |
| 5291 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5292 | |
| 5293 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 5294 | // stack. |
| 5295 | for (int i = 0; i < 4; ++i) { |
| 5296 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5297 | |
| 5298 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5299 | ASSERT_TRUE(response); |
| 5300 | ASSERT_TRUE(response->headers); |
| 5301 | EXPECT_EQ(407, response->headers->response_code()); |
| 5302 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5303 | |
| 5304 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 5305 | } |
| 5306 | |
| 5307 | // One shall be the number thou shalt retry, and the number of the retrying |
| 5308 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 5309 | // that thou then proceed to one. Three is right out. Once the number one, |
| 5310 | // being the first number, be reached, then lobbest thou thy |
| 5311 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 5312 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 5313 | |
| 5314 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5315 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5316 | } |
| 5317 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5318 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 5319 | // that hangs up when credentials are initially sent, and sends a challenge |
| 5320 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5321 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5322 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 5323 | HttpRequestInfo request; |
| 5324 | request.method = "GET"; |
| 5325 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5326 | request.traffic_annotation = |
| 5327 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5328 | |
| 5329 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5330 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5331 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5332 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5333 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5334 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5335 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5336 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5337 | mock_handler->set_allows_default_credentials(true); |
| 5338 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5339 | HttpAuth::AUTH_PROXY); |
| 5340 | // Add another handler for the second challenge. It supports default |
| 5341 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5342 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5343 | mock_handler->set_allows_default_credentials(true); |
| 5344 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5345 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5346 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5347 | |
| 5348 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5349 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5350 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5351 | |
| 5352 | // Should try to establish tunnel. |
| 5353 | MockWrite data_writes1[] = { |
| 5354 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5355 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5356 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5357 | }; |
| 5358 | |
| 5359 | // The proxy responds to the connect with a 407, using a non-persistent |
| 5360 | // connection. |
| 5361 | MockRead data_reads1[] = { |
| 5362 | // No credentials. |
| 5363 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5364 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 5365 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 5366 | }; |
| 5367 | |
| 5368 | // Since the first connection was closed, need to establish another once given |
| 5369 | // credentials. |
| 5370 | MockWrite data_writes2[] = { |
| 5371 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5372 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5373 | "Proxy-Connection: keep-alive\r\n" |
| 5374 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5375 | }; |
| 5376 | |
| 5377 | MockRead data_reads2[] = { |
| 5378 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5379 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 5380 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 5381 | }; |
| 5382 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5383 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5384 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5385 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5386 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5387 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5389 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5390 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5391 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5392 | |
| 5393 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5394 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5395 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5396 | |
| 5397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5398 | ASSERT_TRUE(response); |
| 5399 | ASSERT_TRUE(response->headers); |
| 5400 | EXPECT_EQ(407, response->headers->response_code()); |
| 5401 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5402 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5403 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5404 | |
| 5405 | LoadTimingInfo load_timing_info; |
| 5406 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5407 | |
| 5408 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5409 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5410 | response = trans->GetResponseInfo(); |
| 5411 | ASSERT_TRUE(response); |
| 5412 | ASSERT_TRUE(response->headers); |
| 5413 | EXPECT_EQ(407, response->headers->response_code()); |
| 5414 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5415 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5416 | |
| 5417 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5418 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5419 | } |
| 5420 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5421 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 5422 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 5423 | // unnecessarily invalidated, and that if the server co-operates, the |
| 5424 | // authentication handshake can continue with the same scheme but with a |
| 5425 | // different identity. |
| 5426 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 5427 | HttpRequestInfo request; |
| 5428 | request.method = "GET"; |
| 5429 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5430 | request.traffic_annotation = |
| 5431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5432 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5433 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5434 | auth_handler_factory->set_do_init_from_challenge(true); |
| 5435 | |
| 5436 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5437 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5438 | mock_handler->set_allows_default_credentials(true); |
| 5439 | mock_handler->set_allows_explicit_credentials(true); |
| 5440 | mock_handler->set_connection_based(true); |
| 5441 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 5442 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5443 | HttpAuth::AUTH_SERVER); |
| 5444 | |
| 5445 | // Add another handler for the second challenge. It supports default |
| 5446 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5447 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5448 | mock_handler->set_allows_default_credentials(true); |
| 5449 | mock_handler->set_allows_explicit_credentials(true); |
| 5450 | mock_handler->set_connection_based(true); |
| 5451 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5452 | HttpAuth::AUTH_SERVER); |
| 5453 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 5454 | |
| 5455 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5456 | |
| 5457 | MockWrite data_writes1[] = { |
| 5458 | MockWrite("GET / HTTP/1.1\r\n" |
| 5459 | "Host: www.example.org\r\n" |
| 5460 | "Connection: keep-alive\r\n\r\n"), |
| 5461 | }; |
| 5462 | |
| 5463 | MockRead data_reads1[] = { |
| 5464 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 5465 | "WWW-Authenticate: Mock\r\n" |
| 5466 | "Connection: keep-alive\r\n\r\n"), |
| 5467 | }; |
| 5468 | |
| 5469 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 5470 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 5471 | // transaction procceds without an authorization header. |
| 5472 | MockWrite data_writes2[] = { |
| 5473 | MockWrite("GET / HTTP/1.1\r\n" |
| 5474 | "Host: www.example.org\r\n" |
| 5475 | "Connection: keep-alive\r\n\r\n"), |
| 5476 | }; |
| 5477 | |
| 5478 | MockRead data_reads2[] = { |
| 5479 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 5480 | "WWW-Authenticate: Mock\r\n" |
| 5481 | "Connection: keep-alive\r\n\r\n"), |
| 5482 | }; |
| 5483 | |
| 5484 | MockWrite data_writes3[] = { |
| 5485 | MockWrite("GET / HTTP/1.1\r\n" |
| 5486 | "Host: www.example.org\r\n" |
| 5487 | "Connection: keep-alive\r\n" |
| 5488 | "Authorization: auth_token\r\n\r\n"), |
| 5489 | }; |
| 5490 | |
| 5491 | MockRead data_reads3[] = { |
| 5492 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5493 | "Content-Length: 5\r\n" |
| 5494 | "Content-Type: text/plain\r\n" |
| 5495 | "Connection: keep-alive\r\n\r\n" |
| 5496 | "Hello"), |
| 5497 | }; |
| 5498 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5499 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5500 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5501 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5502 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5503 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5504 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5505 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5506 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5507 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5508 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5509 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5510 | |
| 5511 | TestCompletionCallback callback; |
| 5512 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5513 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5514 | |
| 5515 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5516 | ASSERT_TRUE(response); |
| 5517 | ASSERT_TRUE(response->headers); |
| 5518 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5519 | |
| 5520 | // The following three tests assert that an authentication challenge was |
| 5521 | // received and that the stack is ready to respond to the challenge using |
| 5522 | // ambient credentials. |
| 5523 | EXPECT_EQ(401, response->headers->response_code()); |
| 5524 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5525 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5526 | |
| 5527 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 5528 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5529 | response = trans->GetResponseInfo(); |
| 5530 | ASSERT_TRUE(response); |
| 5531 | ASSERT_TRUE(response->headers); |
| 5532 | |
| 5533 | // The following three tests assert that an authentication challenge was |
| 5534 | // received and that the stack needs explicit credentials before it is ready |
| 5535 | // to respond to the challenge. |
| 5536 | EXPECT_EQ(401, response->headers->response_code()); |
| 5537 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5538 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5539 | |
| 5540 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 5541 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5542 | response = trans->GetResponseInfo(); |
| 5543 | ASSERT_TRUE(response); |
| 5544 | ASSERT_TRUE(response->headers); |
| 5545 | EXPECT_EQ(200, response->headers->response_code()); |
| 5546 | |
| 5547 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5548 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5549 | } |
| 5550 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5551 | // Proxy resolver that returns a proxy with the same host and port for different |
| 5552 | // schemes, based on the path of the URL being requests. |
| 5553 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 5554 | public: |
| 5555 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 5556 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 5557 | |
| 5558 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 5559 | |
| 5560 | static HostPortPair ProxyHostPortPair() { |
| 5561 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 5562 | } |
| 5563 | |
| 5564 | // ProxyResolver implementation. |
| 5565 | int GetProxyForURL(const GURL& url, |
Matt Menke | cd522ee0 | 2019-11-13 19:53:39 | [diff] [blame] | 5566 | const NetworkIsolationKey& network_isolation_key, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5567 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 5568 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5569 | std::unique_ptr<Request>* request, |
| 5570 | const NetLogWithSource& /*net_log*/) override { |
| 5571 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 5572 | results->set_traffic_annotation( |
| 5573 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5574 | if (url.path() == "/socks4") { |
| 5575 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 5576 | return OK; |
| 5577 | } |
| 5578 | if (url.path() == "/socks5") { |
| 5579 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 5580 | return OK; |
| 5581 | } |
| 5582 | if (url.path() == "/http") { |
| 5583 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 5584 | return OK; |
| 5585 | } |
| 5586 | if (url.path() == "/https") { |
| 5587 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 5588 | return OK; |
| 5589 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5590 | if (url.path() == "/https_trusted") { |
| 5591 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5592 | ProxyHostPortPair(), |
| 5593 | true /* is_trusted_proxy */)); |
| 5594 | return OK; |
| 5595 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5596 | NOTREACHED(); |
| 5597 | return ERR_NOT_IMPLEMENTED; |
| 5598 | } |
| 5599 | |
| 5600 | private: |
| 5601 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 5602 | }; |
| 5603 | |
| 5604 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 5605 | : public ProxyResolverFactory { |
| 5606 | public: |
| 5607 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 5608 | : ProxyResolverFactory(false) {} |
| 5609 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 5610 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 5611 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 5612 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 5613 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5614 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 5615 | return OK; |
| 5616 | } |
| 5617 | |
| 5618 | private: |
| 5619 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 5620 | }; |
| 5621 | |
| 5622 | // 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] | 5623 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5624 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 5625 | // request to foo.com using proxy.com as an HTTP proxy. |
| 5626 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5627 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5628 | std::make_unique<ConfiguredProxyResolutionService>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5629 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5630 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5631 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 5632 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5633 | |
| 5634 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5635 | |
| 5636 | MockWrite socks_writes[] = { |
| 5637 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 5638 | kSOCKS4OkRequestLocalHostPort80Length), |
| 5639 | MockWrite(SYNCHRONOUS, |
| 5640 | "GET /socks4 HTTP/1.1\r\n" |
| 5641 | "Host: test\r\n" |
| 5642 | "Connection: keep-alive\r\n\r\n"), |
| 5643 | }; |
| 5644 | MockRead socks_reads[] = { |
| 5645 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 5646 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5647 | "Connection: keep-alive\r\n" |
| 5648 | "Content-Length: 15\r\n\r\n" |
| 5649 | "SOCKS4 Response"), |
| 5650 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5651 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5652 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 5653 | |
| 5654 | const char kSOCKS5Request[] = { |
| 5655 | 0x05, // Version |
| 5656 | 0x01, // Command (CONNECT) |
| 5657 | 0x00, // Reserved |
| 5658 | 0x03, // Address type (DOMAINNAME) |
| 5659 | 0x04, // Length of domain (4) |
| 5660 | 't', 'e', 's', 't', // Domain string |
| 5661 | 0x00, 0x50, // 16-bit port (80) |
| 5662 | }; |
| 5663 | MockWrite socks5_writes[] = { |
| 5664 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5665 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5666 | MockWrite(SYNCHRONOUS, |
| 5667 | "GET /socks5 HTTP/1.1\r\n" |
| 5668 | "Host: test\r\n" |
| 5669 | "Connection: keep-alive\r\n\r\n"), |
| 5670 | }; |
| 5671 | MockRead socks5_reads[] = { |
| 5672 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5673 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5674 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5675 | "Connection: keep-alive\r\n" |
| 5676 | "Content-Length: 15\r\n\r\n" |
| 5677 | "SOCKS5 Response"), |
| 5678 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5679 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5680 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5681 | |
| 5682 | MockWrite http_writes[] = { |
| 5683 | MockWrite(SYNCHRONOUS, |
| 5684 | "GET http://test/http HTTP/1.1\r\n" |
| 5685 | "Host: test\r\n" |
| 5686 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5687 | }; |
| 5688 | MockRead http_reads[] = { |
| 5689 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5690 | "Proxy-Connection: keep-alive\r\n" |
| 5691 | "Content-Length: 13\r\n\r\n" |
| 5692 | "HTTP Response"), |
| 5693 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5694 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5695 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5696 | |
| 5697 | MockWrite https_writes[] = { |
| 5698 | MockWrite(SYNCHRONOUS, |
| 5699 | "GET http://test/https HTTP/1.1\r\n" |
| 5700 | "Host: test\r\n" |
| 5701 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5702 | }; |
| 5703 | MockRead https_reads[] = { |
| 5704 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5705 | "Proxy-Connection: keep-alive\r\n" |
| 5706 | "Content-Length: 14\r\n\r\n" |
| 5707 | "HTTPS Response"), |
| 5708 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5709 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5710 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5711 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5713 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5714 | MockWrite https_trusted_writes[] = { |
| 5715 | MockWrite(SYNCHRONOUS, |
| 5716 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5717 | "Host: test\r\n" |
| 5718 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5719 | }; |
| 5720 | MockRead https_trusted_reads[] = { |
| 5721 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5722 | "Proxy-Connection: keep-alive\r\n" |
| 5723 | "Content-Length: 22\r\n\r\n" |
| 5724 | "HTTPS Trusted Response"), |
| 5725 | }; |
| 5726 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5727 | https_trusted_writes); |
| 5728 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5729 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5731 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5732 | struct TestCase { |
| 5733 | GURL url; |
| 5734 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5735 | // 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] | 5736 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5737 | int expected_idle_socks4_sockets; |
| 5738 | int expected_idle_socks5_sockets; |
| 5739 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5740 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5741 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5742 | int expected_idle_https_sockets; |
| 5743 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5744 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5745 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5746 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5747 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5748 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5749 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5750 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5751 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5752 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5753 | }; |
| 5754 | |
| 5755 | for (const auto& test_case : kTestCases) { |
| 5756 | HttpRequestInfo request; |
| 5757 | request.method = "GET"; |
| 5758 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5759 | request.traffic_annotation = |
| 5760 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5761 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5762 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5763 | session.get()); |
| 5764 | TestCompletionCallback callback; |
| 5765 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5766 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5767 | |
| 5768 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5769 | ASSERT_TRUE(response); |
| 5770 | ASSERT_TRUE(response->headers); |
| 5771 | EXPECT_EQ(200, response->headers->response_code()); |
| 5772 | std::string response_data; |
| 5773 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5774 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5775 | |
| 5776 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5777 | // the next requests. |
| 5778 | trans.reset(); |
| 5779 | base::RunLoop().RunUntilIdle(); |
| 5780 | |
| 5781 | // Check the number of idle sockets in the pool, to make sure that used |
| 5782 | // sockets are indeed being returned to the socket pool. If each request |
| 5783 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5784 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5785 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5786 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5787 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5788 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5789 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5790 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5791 | ProxyHostPortPair())) |
| 5792 | ->IdleSocketCount()); |
| 5793 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5794 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5795 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5796 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5797 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5798 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5799 | ProxyHostPortPair())) |
| 5800 | ->IdleSocketCount()); |
| 5801 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5802 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5803 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5804 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5805 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5806 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5807 | ProxyHostPortPair())) |
| 5808 | ->IdleSocketCount()); |
| 5809 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5810 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5811 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5812 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5813 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5814 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5815 | ProxyHostPortPair())) |
| 5816 | ->IdleSocketCount()); |
| 5817 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5818 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5819 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5820 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5821 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5822 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5823 | ProxyHostPortPair(), |
| 5824 | true /* is_trusted_proxy */)) |
| 5825 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5826 | } |
| 5827 | } |
| 5828 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5829 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5830 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5831 | HttpRequestInfo request1; |
| 5832 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5833 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5834 | request1.traffic_annotation = |
| 5835 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5836 | |
| 5837 | HttpRequestInfo request2; |
| 5838 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5839 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5840 | request2.traffic_annotation = |
| 5841 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5842 | |
| 5843 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5844 | session_deps_.proxy_resolution_service = |
| 5845 | ConfiguredProxyResolutionService::CreateFixed( |
| 5846 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 5847 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5848 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5850 | |
| 5851 | // Since we have proxy, should try to establish tunnel. |
| 5852 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5853 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5854 | "Host: www.example.org:443\r\n" |
| 5855 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5856 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5857 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5858 | "Host: www.example.org\r\n" |
| 5859 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5860 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5861 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5862 | "Host: www.example.org\r\n" |
| 5863 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5864 | }; |
| 5865 | |
| 5866 | // The proxy responds to the connect with a 407, using a persistent |
| 5867 | // connection. |
| 5868 | MockRead data_reads1[] = { |
| 5869 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5870 | |
| 5871 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5872 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5873 | MockRead(SYNCHRONOUS, "1"), |
| 5874 | |
| 5875 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5876 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5877 | MockRead(SYNCHRONOUS, "22"), |
| 5878 | }; |
| 5879 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5880 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5881 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5882 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5884 | |
| 5885 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5886 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5887 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5888 | |
| 5889 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5891 | |
| 5892 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5894 | |
| 5895 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5896 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5897 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5898 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5899 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5900 | |
| 5901 | LoadTimingInfo load_timing_info1; |
| 5902 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5903 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5904 | |
| 5905 | trans1.reset(); |
| 5906 | |
| 5907 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5908 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5909 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5910 | |
| 5911 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5913 | |
| 5914 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5915 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5916 | |
| 5917 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5918 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5919 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5920 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5921 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5922 | |
| 5923 | LoadTimingInfo load_timing_info2; |
| 5924 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5925 | TestLoadTimingReused(load_timing_info2); |
| 5926 | |
| 5927 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5928 | |
| 5929 | trans2.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5930 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | // 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] | 5934 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5935 | HttpRequestInfo request1; |
| 5936 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5937 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5938 | request1.traffic_annotation = |
| 5939 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5940 | |
| 5941 | HttpRequestInfo request2; |
| 5942 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5943 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5944 | request2.traffic_annotation = |
| 5945 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5946 | |
| 5947 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5948 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5949 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5950 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 5951 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5952 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5953 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5954 | |
| 5955 | // Since we have proxy, should try to establish tunnel. |
| 5956 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5957 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5958 | "Host: www.example.org:443\r\n" |
| 5959 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5960 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5961 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5962 | "Host: www.example.org\r\n" |
| 5963 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5964 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5965 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5966 | "Host: www.example.org\r\n" |
| 5967 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5968 | }; |
| 5969 | |
| 5970 | // The proxy responds to the connect with a 407, using a persistent |
| 5971 | // connection. |
| 5972 | MockRead data_reads1[] = { |
| 5973 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5974 | |
| 5975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5976 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5977 | MockRead(SYNCHRONOUS, "1"), |
| 5978 | |
| 5979 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5980 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5981 | MockRead(SYNCHRONOUS, "22"), |
| 5982 | }; |
| 5983 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5984 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5985 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5986 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5987 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5988 | |
| 5989 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5990 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5991 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5992 | |
| 5993 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5995 | |
| 5996 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5998 | |
| 5999 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6000 | ASSERT_TRUE(response1); |
| 6001 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6002 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 6003 | |
| 6004 | LoadTimingInfo load_timing_info1; |
| 6005 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 6006 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 6007 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6008 | |
| 6009 | trans1.reset(); |
| 6010 | |
| 6011 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6012 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6013 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6014 | |
| 6015 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6017 | |
| 6018 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6019 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6020 | |
| 6021 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6022 | ASSERT_TRUE(response2); |
| 6023 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6024 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 6025 | |
| 6026 | LoadTimingInfo load_timing_info2; |
| 6027 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6028 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 6029 | |
| 6030 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 6031 | |
| 6032 | trans2.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 6033 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6034 | } |
| 6035 | |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 6036 | // Make sure that NetworkIsolationKeys are passed down to the proxy layer. |
| 6037 | TEST_F(HttpNetworkTransactionTest, ProxyResolvedWithNetworkIsolationKey) { |
| 6038 | const url::Origin kOrigin = url::Origin::Create(GURL("https://foo.test/")); |
| 6039 | const net::NetworkIsolationKey kNetworkIsolationKey(kOrigin, kOrigin); |
| 6040 | |
| 6041 | ProxyConfig proxy_config; |
| 6042 | proxy_config.set_auto_detect(true); |
| 6043 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6044 | |
| 6045 | CapturingProxyResolver capturing_proxy_resolver; |
| 6046 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6047 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6048 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 6049 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6050 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6051 | std::make_unique<CapturingProxyResolverFactory>( |
| 6052 | &capturing_proxy_resolver), |
| 6053 | nullptr); |
| 6054 | |
| 6055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6056 | |
| 6057 | // No need to continue with the network request - proxy resolution occurs |
| 6058 | // before establishing a data. |
| 6059 | StaticSocketDataProvider data{base::span<MockRead>(), |
| 6060 | base::span<MockWrite>()}; |
| 6061 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_FAILED)); |
| 6062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6063 | |
| 6064 | // Run first request until an auth challenge is observed. |
| 6065 | HttpRequestInfo request; |
| 6066 | request.method = "GET"; |
| 6067 | request.url = GURL("http://foo.test/"); |
| 6068 | request.traffic_annotation = |
| 6069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6070 | HttpNetworkTransaction trans(LOWEST, session.get()); |
| 6071 | TestCompletionCallback callback; |
| 6072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 6073 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_FAILED)); |
| 6074 | } |
| 6075 | |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 6076 | // Test that a failure in resolving the proxy hostname is retrievable. |
| 6077 | TEST_F(HttpNetworkTransactionTest, ProxyHostResolutionFailure) { |
| 6078 | HttpRequestInfo request; |
| 6079 | request.method = "GET"; |
| 6080 | request.url = GURL("http://www.example.org/"); |
| 6081 | request.traffic_annotation = |
| 6082 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6083 | |
| 6084 | RecordingTestNetLog log; |
| 6085 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6086 | session_deps_.proxy_resolution_service = |
| 6087 | ConfiguredProxyResolutionService::CreateFixed( |
| 6088 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 6089 | MockHostResolver* resolver = new MockHostResolver(); |
| 6090 | resolver->rules()->AddSimulatedTimeoutFailure("proxy"); |
| 6091 | session_deps_.net_log = &log; |
| 6092 | session_deps_.host_resolver.reset(resolver); |
| 6093 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 6094 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6095 | TestCompletionCallback callback; |
| 6096 | |
| 6097 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 6098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6099 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PROXY_CONNECTION_FAILED)); |
| 6100 | |
| 6101 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6102 | ASSERT_TRUE(response); |
| 6103 | EXPECT_THAT(response->resolve_error_info.error, IsError(ERR_DNS_TIMED_OUT)); |
| 6104 | } |
| 6105 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6106 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6107 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6108 | HttpRequestInfo request; |
| 6109 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6110 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6111 | request.traffic_annotation = |
| 6112 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6113 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6114 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6115 | session_deps_.proxy_resolution_service = |
| 6116 | ConfiguredProxyResolutionService::CreateFixed( |
| 6117 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6118 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6119 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6121 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6122 | // Since we have proxy, should use full url |
| 6123 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6124 | MockWrite( |
| 6125 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6126 | "Host: www.example.org\r\n" |
| 6127 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6128 | }; |
| 6129 | |
| 6130 | MockRead data_reads1[] = { |
| 6131 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6132 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6133 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6134 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6135 | }; |
| 6136 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6137 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6138 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6139 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6142 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6147 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6148 | |
| 6149 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6150 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6151 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6152 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6154 | TestLoadTimingNotReused(load_timing_info, |
| 6155 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6157 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6158 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6159 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 6160 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6161 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6162 | EXPECT_EQ(200, response->headers->response_code()); |
| 6163 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6164 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6165 | |
| 6166 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6167 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6168 | } |
| 6169 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6170 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6171 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6172 | HttpRequestInfo request; |
| 6173 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6174 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6175 | request.traffic_annotation = |
| 6176 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6177 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6178 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6179 | session_deps_.proxy_resolution_service = |
| 6180 | ConfiguredProxyResolutionService::CreateFixed( |
| 6181 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6182 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6183 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6184 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6185 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6186 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6187 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6188 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6189 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6190 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6191 | spdy::SpdySerializedFrame resp( |
| 6192 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6193 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6194 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6195 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6196 | }; |
| 6197 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6198 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6199 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6200 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6201 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6202 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6205 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6209 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6211 | |
| 6212 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6213 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6214 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6215 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6216 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6217 | TestLoadTimingNotReused(load_timing_info, |
| 6218 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6221 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 6222 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6223 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6224 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6225 | |
| 6226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6227 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6228 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6229 | } |
| 6230 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6231 | // Verifies that a session which races and wins against the owning transaction |
| 6232 | // (completing prior to host resolution), doesn't fail the transaction. |
| 6233 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6234 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6235 | HttpRequestInfo request; |
| 6236 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6237 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6238 | request.traffic_annotation = |
| 6239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6240 | |
| 6241 | // Configure SPDY proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6242 | session_deps_.proxy_resolution_service = |
| 6243 | ConfiguredProxyResolutionService::CreateFixed( |
| 6244 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6245 | RecordingBoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6246 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6248 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6249 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6250 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6251 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6252 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6253 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6254 | spdy::SpdySerializedFrame resp( |
| 6255 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6256 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6257 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6258 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6259 | }; |
| 6260 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6261 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6262 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 6263 | |
| 6264 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6265 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6267 | |
| 6268 | TestCompletionCallback callback1; |
| 6269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6270 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6271 | |
| 6272 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6273 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 6274 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6275 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6277 | |
| 6278 | // Race a session to the proxy, which completes first. |
| 6279 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 6280 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6281 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 6282 | SpdySessionKey::IsProxySession::kTrue, SocketTag(), |
| 6283 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6284 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 6285 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6286 | |
| 6287 | // Unstall the resolution begun by the transaction. |
| 6288 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 6289 | session_deps_.host_resolver->ResolveAllPending(); |
| 6290 | |
| 6291 | EXPECT_FALSE(callback1.have_result()); |
| 6292 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6293 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6295 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6296 | ASSERT_TRUE(response); |
| 6297 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6298 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6299 | |
| 6300 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6301 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6302 | EXPECT_EQ(kUploadData, response_data); |
| 6303 | } |
| 6304 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6305 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6306 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6307 | HttpRequestInfo request; |
| 6308 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6309 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6310 | request.traffic_annotation = |
| 6311 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6312 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6313 | // Configure against https proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6314 | session_deps_.proxy_resolution_service = |
| 6315 | ConfiguredProxyResolutionService::CreateFixed( |
| 6316 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6317 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6318 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6319 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6320 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6321 | // The first request will be a bare GET, the second request will be a |
| 6322 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6323 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6324 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 6325 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6326 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6327 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6328 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6329 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6330 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 6331 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 6332 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6333 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6334 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6335 | }; |
| 6336 | |
| 6337 | // The first response is a 407 proxy authentication challenge, and the second |
| 6338 | // response will be a 200 response since the second request includes a valid |
| 6339 | // Authorization header. |
| 6340 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6341 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6342 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6343 | spdy::SpdySerializedFrame resp_authentication( |
| 6344 | spdy_util_.ConstructSpdyReplyError( |
| 6345 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 6346 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6347 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6348 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6349 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6350 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6351 | spdy::SpdySerializedFrame body_data( |
| 6352 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6353 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6354 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6355 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6356 | CreateMockRead(resp_data, 4), |
| 6357 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6358 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6359 | }; |
| 6360 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6361 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6363 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6364 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6365 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6368 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6372 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6373 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6374 | |
| 6375 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6376 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6378 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6379 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6380 | ASSERT_TRUE(response); |
| 6381 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6382 | EXPECT_EQ(407, response->headers->response_code()); |
| 6383 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6384 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6386 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6388 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6390 | |
| 6391 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6394 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6395 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6396 | ASSERT_TRUE(response_restart); |
| 6397 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6398 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 6399 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6400 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6401 | } |
| 6402 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6403 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6404 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6405 | HttpRequestInfo request; |
| 6406 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6407 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6408 | request.traffic_annotation = |
| 6409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6410 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6411 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6412 | session_deps_.proxy_resolution_service = |
| 6413 | ConfiguredProxyResolutionService::CreateFixed( |
| 6414 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6415 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6416 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6420 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6421 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6422 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6423 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6424 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6425 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6426 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6427 | const char get[] = |
| 6428 | "GET / HTTP/1.1\r\n" |
| 6429 | "Host: www.example.org\r\n" |
| 6430 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6431 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6432 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6433 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6434 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6435 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6436 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6437 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6438 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6439 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6440 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6441 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6442 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6443 | |
| 6444 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6445 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 6446 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6447 | }; |
| 6448 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6449 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6450 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6451 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 6452 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 6453 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6454 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6455 | }; |
| 6456 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6457 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6458 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6459 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6460 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6461 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6463 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6464 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6466 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6468 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6470 | |
| 6471 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6472 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6473 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6474 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6475 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6476 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6479 | ASSERT_TRUE(response); |
| 6480 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6481 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6482 | |
| 6483 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6484 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6485 | EXPECT_EQ("1234567890", response_data); |
| 6486 | } |
| 6487 | |
| 6488 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6489 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 6490 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6491 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6492 | HttpRequestInfo request; |
| 6493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6494 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6495 | request.traffic_annotation = |
| 6496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6497 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6498 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6499 | session_deps_.proxy_resolution_service = |
| 6500 | ConfiguredProxyResolutionService::CreateFixed( |
| 6501 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6502 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6503 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6506 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6507 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6508 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6509 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6510 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6511 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6512 | // fetch https://www.example.org/ via SPDY |
| 6513 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6514 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 6515 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6516 | spdy::SpdySerializedFrame wrapped_get( |
| 6517 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6518 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6519 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6520 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6521 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6522 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6523 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6524 | spdy::SpdySerializedFrame body( |
| 6525 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 6526 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6527 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6528 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6529 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6530 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6531 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6532 | |
| 6533 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6534 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 6535 | CreateMockWrite(window_update_get_resp, 6), |
| 6536 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6537 | }; |
| 6538 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6539 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6540 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 6541 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6542 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6543 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6544 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6545 | }; |
| 6546 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6547 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6548 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6549 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6550 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6551 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6553 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6554 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6555 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6557 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6559 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6561 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 6562 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6563 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 6564 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 6565 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6566 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6567 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6568 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6569 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6570 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6571 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6573 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6574 | ASSERT_TRUE(response); |
| 6575 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6576 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6577 | |
| 6578 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6579 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6580 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6581 | } |
| 6582 | |
| 6583 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6584 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6585 | HttpRequestInfo request; |
| 6586 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6587 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6588 | request.traffic_annotation = |
| 6589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6590 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6591 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6592 | session_deps_.proxy_resolution_service = |
| 6593 | ConfiguredProxyResolutionService::CreateFixed( |
| 6594 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6595 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6596 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6598 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6600 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6601 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6602 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6603 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6604 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6605 | spdy::SpdySerializedFrame get( |
| 6606 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6607 | |
| 6608 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6609 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6610 | }; |
| 6611 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6612 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 6613 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6614 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6615 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6616 | }; |
| 6617 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6618 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6619 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6620 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6621 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6622 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6624 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6625 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6628 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6630 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6632 | |
| 6633 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6634 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6635 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 6636 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6637 | } |
| 6638 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6639 | // 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] | 6640 | // is observed, but does exist by the time auth credentials are provided. In |
| 6641 | // this case, auth and SSL are fully negotated on the second request, but then |
| 6642 | // the socket is discarded to use the shared session. |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6643 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 6644 | ProxyConfig proxy_config; |
| 6645 | proxy_config.set_auto_detect(true); |
| 6646 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6647 | |
| 6648 | CapturingProxyResolver capturing_proxy_resolver; |
| 6649 | capturing_proxy_resolver.set_proxy_server( |
| 6650 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 6651 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6652 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6653 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6654 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6655 | std::make_unique<CapturingProxyResolverFactory>( |
| 6656 | &capturing_proxy_resolver), |
| 6657 | nullptr); |
| 6658 | |
| 6659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6660 | |
| 6661 | const char kMyUrl[] = "https://www.example.org/"; |
| 6662 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6663 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6664 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6665 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 6666 | |
| 6667 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6668 | spdy::SpdySerializedFrame get2( |
| 6669 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 6670 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6671 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6672 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 6673 | |
| 6674 | MockWrite auth_challenge_writes[] = { |
| 6675 | MockWrite(ASYNC, 0, |
| 6676 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6677 | "Host: www.example.org:443\r\n" |
| 6678 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6679 | MockWrite(ASYNC, 2, |
| 6680 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6681 | "Host: www.example.org:443\r\n" |
| 6682 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6683 | }; |
| 6684 | |
| 6685 | MockRead auth_challenge_reads[] = { |
| 6686 | MockRead(ASYNC, 1, |
| 6687 | "HTTP/1.1 407 Authentication Required\r\n" |
| 6688 | "Content-Length: 0\r\n" |
| 6689 | "Proxy-Connection: close\r\n" |
| 6690 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 6691 | }; |
| 6692 | |
| 6693 | MockWrite spdy_writes[] = { |
| 6694 | MockWrite(ASYNC, 0, |
| 6695 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6696 | "Host: www.example.org:443\r\n" |
| 6697 | "Proxy-Connection: keep-alive\r\n" |
| 6698 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 6699 | CreateMockWrite(get, 2), |
| 6700 | CreateMockWrite(get2, 5), |
| 6701 | }; |
| 6702 | |
| 6703 | MockRead spdy_reads[] = { |
| 6704 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 6705 | CreateMockRead(get_resp, 3, ASYNC), |
| 6706 | CreateMockRead(body, 4, ASYNC), |
| 6707 | CreateMockRead(get_resp2, 6, ASYNC), |
| 6708 | CreateMockRead(body2, 7, ASYNC), |
| 6709 | |
| 6710 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 6711 | }; |
| 6712 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6713 | MockWrite auth_response_writes_discarded_socket[] = { |
| 6714 | MockWrite(ASYNC, 0, |
| 6715 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6716 | "Host: www.example.org:443\r\n" |
| 6717 | "Proxy-Connection: keep-alive\r\n" |
| 6718 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 6719 | }; |
| 6720 | |
| 6721 | MockRead auth_response_reads_discarded_socket[] = { |
| 6722 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 6723 | }; |
| 6724 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6725 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 6726 | auth_challenge_writes); |
| 6727 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 6728 | |
| 6729 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 6730 | auth_challenge_writes); |
| 6731 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 6732 | |
| 6733 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 6734 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 6735 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6736 | SequencedSocketData auth_response_discarded_socket( |
| 6737 | auth_response_reads_discarded_socket, |
| 6738 | auth_response_writes_discarded_socket); |
| 6739 | session_deps_.socket_factory->AddSocketDataProvider( |
| 6740 | &auth_response_discarded_socket); |
| 6741 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6742 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6743 | ssl.next_proto = kProtoHTTP2; |
| 6744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6745 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6746 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6747 | ssl2.next_proto = kProtoHTTP2; |
| 6748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6749 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6750 | TestCompletionCallback callback; |
| 6751 | std::string response_data; |
| 6752 | |
| 6753 | // Run first request until an auth challenge is observed. |
| 6754 | HttpRequestInfo request1; |
| 6755 | request1.method = "GET"; |
| 6756 | request1.url = GURL(kMyUrl); |
| 6757 | request1.traffic_annotation = |
| 6758 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6759 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6760 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6761 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6762 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6763 | ASSERT_TRUE(response); |
| 6764 | ASSERT_TRUE(response->headers); |
| 6765 | EXPECT_EQ(407, response->headers->response_code()); |
| 6766 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6767 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6768 | |
| 6769 | // Run second request until an auth challenge is observed. |
| 6770 | HttpRequestInfo request2; |
| 6771 | request2.method = "GET"; |
| 6772 | request2.url = GURL(kMyUrl); |
| 6773 | request2.traffic_annotation = |
| 6774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6775 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6776 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6777 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6778 | response = trans2.GetResponseInfo(); |
| 6779 | ASSERT_TRUE(response); |
| 6780 | ASSERT_TRUE(response->headers); |
| 6781 | EXPECT_EQ(407, response->headers->response_code()); |
| 6782 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6783 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6784 | |
| 6785 | // Now provide credentials for the first request, and wait for it to complete. |
| 6786 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6787 | rv = callback.GetResult(rv); |
| 6788 | EXPECT_THAT(rv, IsOk()); |
| 6789 | response = trans1.GetResponseInfo(); |
| 6790 | ASSERT_TRUE(response); |
| 6791 | ASSERT_TRUE(response->headers); |
| 6792 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6793 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6794 | EXPECT_EQ(kUploadData, response_data); |
| 6795 | |
| 6796 | // Now provide credentials for the second request. It should notice the |
| 6797 | // existing session, and reuse it. |
| 6798 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6799 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6800 | response = trans2.GetResponseInfo(); |
| 6801 | ASSERT_TRUE(response); |
| 6802 | ASSERT_TRUE(response->headers); |
| 6803 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6804 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6805 | EXPECT_EQ(kUploadData, response_data); |
| 6806 | } |
| 6807 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6808 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6809 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6810 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6811 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6812 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6813 | session_deps_.proxy_resolution_service = |
| 6814 | ConfiguredProxyResolutionService::CreateFixed( |
| 6815 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6816 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6817 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6818 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6819 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6820 | |
| 6821 | HttpRequestInfo request1; |
| 6822 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6823 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6824 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6825 | request1.traffic_annotation = |
| 6826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6827 | |
| 6828 | HttpRequestInfo request2; |
| 6829 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6830 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6831 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6832 | request2.traffic_annotation = |
| 6833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6834 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6835 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6836 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6837 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6838 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6839 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6840 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6841 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6842 | // Fetch https://www.example.org/ via HTTP. |
| 6843 | const char get1[] = |
| 6844 | "GET / HTTP/1.1\r\n" |
| 6845 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6846 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6847 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6848 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6849 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6850 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6851 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6852 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6853 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6854 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6855 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6856 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6857 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6858 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6859 | spdy::SpdyHeaderBlock connect2_block; |
| 6860 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6861 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6862 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6863 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6864 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6865 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6866 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6867 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6868 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6869 | // Fetch https://mail.example.org/ via HTTP. |
| 6870 | const char get2[] = |
| 6871 | "GET / HTTP/1.1\r\n" |
| 6872 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6873 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6874 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6875 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6876 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6877 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6878 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6879 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6880 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6881 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6882 | |
| 6883 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6884 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6885 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6886 | }; |
| 6887 | |
| 6888 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6889 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6890 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6891 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6892 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6893 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6894 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6895 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6896 | }; |
| 6897 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6898 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6899 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6900 | |
| 6901 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6902 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6904 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6906 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6907 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6908 | |
| 6909 | TestCompletionCallback callback; |
| 6910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6912 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6913 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6914 | |
| 6915 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6916 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6917 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6919 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6920 | ASSERT_TRUE(response); |
| 6921 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6922 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6923 | |
| 6924 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6925 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6926 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6927 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6929 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6930 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6931 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6932 | |
| 6933 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6934 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6935 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6936 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6937 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6938 | |
| 6939 | // The requests should have different IDs, since they each are using their own |
| 6940 | // separate stream. |
| 6941 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6943 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6944 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6945 | } |
| 6946 | |
| 6947 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6948 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6949 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6950 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6951 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6952 | session_deps_.proxy_resolution_service = |
| 6953 | ConfiguredProxyResolutionService::CreateFixed( |
| 6954 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6955 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6956 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6957 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6958 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6959 | |
| 6960 | HttpRequestInfo request1; |
| 6961 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6962 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6963 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6964 | request1.traffic_annotation = |
| 6965 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6966 | |
| 6967 | HttpRequestInfo request2; |
| 6968 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6969 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6970 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6971 | request2.traffic_annotation = |
| 6972 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6973 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6974 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6975 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6976 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6977 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6978 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6979 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6980 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6981 | // Fetch https://www.example.org/ via HTTP. |
| 6982 | const char get1[] = |
| 6983 | "GET / HTTP/1.1\r\n" |
| 6984 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6985 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6986 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6987 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6988 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6989 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6990 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6991 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6992 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6993 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6994 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6995 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6996 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6997 | // Fetch https://www.example.org/2 via HTTP. |
| 6998 | const char get2[] = |
| 6999 | "GET /2 HTTP/1.1\r\n" |
| 7000 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7001 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7002 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7003 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7004 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 7005 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7006 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7007 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7008 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7009 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7010 | |
| 7011 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7012 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 7013 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7014 | }; |
| 7015 | |
| 7016 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7017 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 7018 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 7019 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7020 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 7021 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7022 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7023 | }; |
| 7024 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7025 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7026 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7027 | |
| 7028 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7029 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7031 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7033 | |
| 7034 | TestCompletionCallback callback; |
| 7035 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7036 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7037 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7038 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7040 | |
| 7041 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7042 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7043 | |
| 7044 | LoadTimingInfo load_timing_info; |
| 7045 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7046 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 7047 | |
| 7048 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7049 | ASSERT_TRUE(response); |
| 7050 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7051 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7052 | |
| 7053 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 7054 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7055 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7056 | trans.reset(); |
| 7057 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7058 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7059 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7060 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7061 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7062 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7063 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7064 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7065 | |
| 7066 | LoadTimingInfo load_timing_info2; |
| 7067 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 7068 | TestLoadTimingReused(load_timing_info2); |
| 7069 | |
| 7070 | // The requests should have the same ID. |
| 7071 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 7072 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7073 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7074 | } |
| 7075 | |
| 7076 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 7077 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7078 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7079 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7080 | session_deps_.proxy_resolution_service = |
| 7081 | ConfiguredProxyResolutionService::CreateFixed( |
| 7082 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 7083 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7084 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7085 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7086 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7087 | |
| 7088 | HttpRequestInfo request1; |
| 7089 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7090 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7091 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7092 | request1.traffic_annotation = |
| 7093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7094 | |
| 7095 | HttpRequestInfo request2; |
| 7096 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7097 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7098 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7099 | request2.traffic_annotation = |
| 7100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7101 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7102 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7103 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7104 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7105 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7106 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7107 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7108 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7109 | spdy::SpdySerializedFrame body1( |
| 7110 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7111 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7112 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7113 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7114 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7115 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7116 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7117 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7118 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7119 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7120 | spdy::SpdySerializedFrame body2( |
| 7121 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7122 | |
| 7123 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7124 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7125 | }; |
| 7126 | |
| 7127 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7128 | CreateMockRead(get_resp1, 1, ASYNC), |
| 7129 | CreateMockRead(body1, 2, ASYNC), |
| 7130 | CreateMockRead(get_resp2, 4, ASYNC), |
| 7131 | CreateMockRead(body2, 5, ASYNC), |
| 7132 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7133 | }; |
| 7134 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7135 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7136 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7137 | |
| 7138 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7139 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7141 | |
| 7142 | TestCompletionCallback callback; |
| 7143 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7144 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7145 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7146 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7147 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7148 | |
| 7149 | LoadTimingInfo load_timing_info; |
| 7150 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7151 | TestLoadTimingNotReused(load_timing_info, |
| 7152 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7153 | |
| 7154 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7155 | ASSERT_TRUE(response); |
| 7156 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 7157 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7158 | |
| 7159 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 7160 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7161 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 7162 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7163 | // Delete the first request, so the second one can reuse the socket. |
| 7164 | trans.reset(); |
| 7165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7166 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7167 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7168 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7169 | |
| 7170 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7171 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7172 | TestLoadTimingReused(load_timing_info2); |
| 7173 | |
| 7174 | // The requests should have the same ID. |
| 7175 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 7176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7177 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7178 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7179 | } |
| 7180 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7181 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 7182 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 7183 | // would break socket pool isolation. |
| 7184 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 7185 | ProxyConfig proxy_config; |
| 7186 | proxy_config.set_auto_detect(true); |
| 7187 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 7188 | |
| 7189 | CapturingProxyResolver capturing_proxy_resolver; |
| 7190 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7191 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7192 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 7193 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 7194 | std::make_unique<CapturingProxyResolverFactory>( |
| 7195 | &capturing_proxy_resolver), |
| 7196 | nullptr); |
| 7197 | |
| 7198 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7199 | |
| 7200 | SpdyTestUtil spdy_util1; |
| 7201 | // CONNECT to www.example.org:443 via HTTP/2. |
| 7202 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7203 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7204 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7205 | // fetch https://www.example.org/ via HTTP/2. |
| 7206 | const char kMyUrl[] = "https://www.example.org/"; |
| 7207 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 7208 | spdy::SpdySerializedFrame wrapped_get( |
| 7209 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 7210 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7211 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7212 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7213 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7214 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 7215 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 7216 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 7217 | spdy::SpdySerializedFrame wrapped_body( |
| 7218 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 7219 | spdy::SpdySerializedFrame window_update_get_resp( |
| 7220 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 7221 | spdy::SpdySerializedFrame window_update_body( |
| 7222 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 7223 | |
| 7224 | MockWrite spdy_writes1[] = { |
| 7225 | CreateMockWrite(connect, 0), |
| 7226 | CreateMockWrite(wrapped_get, 2), |
| 7227 | CreateMockWrite(window_update_get_resp, 6), |
| 7228 | CreateMockWrite(window_update_body, 7), |
| 7229 | }; |
| 7230 | |
| 7231 | MockRead spdy_reads1[] = { |
| 7232 | CreateMockRead(conn_resp, 1, ASYNC), |
| 7233 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 7234 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 7235 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 7236 | MockRead(ASYNC, 0, 8), |
| 7237 | }; |
| 7238 | |
| 7239 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 7240 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 7241 | |
| 7242 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 7243 | // a new pipe. |
| 7244 | SpdyTestUtil spdy_util2; |
| 7245 | spdy::SpdySerializedFrame req( |
| 7246 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 7247 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 7248 | |
| 7249 | spdy::SpdySerializedFrame resp( |
| 7250 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7251 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 7252 | MockRead spdy_reads2[] = { |
| 7253 | CreateMockRead(resp, 1), |
| 7254 | CreateMockRead(data, 2), |
| 7255 | MockRead(ASYNC, 0, 3), |
| 7256 | }; |
| 7257 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 7258 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 7259 | |
| 7260 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7261 | ssl.next_proto = kProtoHTTP2; |
| 7262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7263 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7264 | ssl2.next_proto = kProtoHTTP2; |
| 7265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7266 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7267 | ssl3.next_proto = kProtoHTTP2; |
| 7268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7269 | |
| 7270 | TestCompletionCallback callback; |
| 7271 | std::string response_data; |
| 7272 | |
| 7273 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 7274 | capturing_proxy_resolver.set_proxy_server( |
| 7275 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 7276 | HttpRequestInfo request1; |
| 7277 | request1.method = "GET"; |
| 7278 | request1.url = GURL("https://www.example.org/"); |
| 7279 | request1.traffic_annotation = |
| 7280 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7281 | |
| 7282 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 7283 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 7284 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7285 | |
| 7286 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 7287 | base::RunLoop().RunUntilIdle(); |
| 7288 | // Now allow the read of the response to complete. |
| 7289 | spdy_data1.Resume(); |
| 7290 | rv = callback.WaitForResult(); |
| 7291 | EXPECT_THAT(rv, IsOk()); |
| 7292 | |
| 7293 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 7294 | ASSERT_TRUE(response); |
| 7295 | ASSERT_TRUE(response->headers); |
| 7296 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 7297 | |
| 7298 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 7299 | EXPECT_EQ(kUploadData, response_data); |
| 7300 | RunUntilIdle(); |
| 7301 | |
| 7302 | // Make a direct HTTP/2 request to proxy:70. |
| 7303 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 7304 | HttpRequestInfo request2; |
| 7305 | request2.method = "GET"; |
| 7306 | request2.url = GURL("https://proxy:70/"); |
| 7307 | request2.traffic_annotation = |
| 7308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7309 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 7310 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 7311 | NetLogWithSource())), |
| 7312 | IsOk()); |
| 7313 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 7314 | } |
| 7315 | |
| 7316 | // Same as above, but reverse request order, since the code to check for an |
| 7317 | // existing session is different for tunnels and direct connections. |
| 7318 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 7319 | // Configure against https proxy server "myproxy:80". |
| 7320 | ProxyConfig proxy_config; |
| 7321 | proxy_config.set_auto_detect(true); |
| 7322 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 7323 | |
| 7324 | CapturingProxyResolver capturing_proxy_resolver; |
| 7325 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7326 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7327 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 7328 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 7329 | std::make_unique<CapturingProxyResolverFactory>( |
| 7330 | &capturing_proxy_resolver), |
| 7331 | nullptr); |
| 7332 | |
| 7333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7334 | // Fetch https://proxy:70/ via HTTP/2. |
| 7335 | SpdyTestUtil spdy_util1; |
| 7336 | spdy::SpdySerializedFrame req( |
| 7337 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 7338 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 7339 | |
| 7340 | spdy::SpdySerializedFrame resp( |
| 7341 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7342 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 7343 | MockRead spdy_reads1[] = { |
| 7344 | CreateMockRead(resp, 1), |
| 7345 | CreateMockRead(data, 2), |
| 7346 | MockRead(ASYNC, 0, 3), |
| 7347 | }; |
| 7348 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 7349 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 7350 | |
| 7351 | SpdyTestUtil spdy_util2; |
| 7352 | // CONNECT to www.example.org:443 via HTTP/2. |
| 7353 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7354 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7355 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7356 | // fetch https://www.example.org/ via HTTP/2. |
| 7357 | const char kMyUrl[] = "https://www.example.org/"; |
| 7358 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 7359 | spdy::SpdySerializedFrame wrapped_get( |
| 7360 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 7361 | spdy::SpdySerializedFrame conn_resp( |
| 7362 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7363 | spdy::SpdySerializedFrame get_resp( |
| 7364 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7365 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 7366 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 7367 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 7368 | spdy::SpdySerializedFrame wrapped_body( |
| 7369 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 7370 | spdy::SpdySerializedFrame window_update_get_resp( |
| 7371 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 7372 | spdy::SpdySerializedFrame window_update_body( |
| 7373 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 7374 | |
| 7375 | MockWrite spdy_writes2[] = { |
| 7376 | CreateMockWrite(connect, 0), |
| 7377 | CreateMockWrite(wrapped_get, 2), |
| 7378 | CreateMockWrite(window_update_get_resp, 6), |
| 7379 | CreateMockWrite(window_update_body, 7), |
| 7380 | }; |
| 7381 | |
| 7382 | MockRead spdy_reads2[] = { |
| 7383 | CreateMockRead(conn_resp, 1, ASYNC), |
| 7384 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 7385 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 7386 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 7387 | MockRead(ASYNC, 0, 8), |
| 7388 | }; |
| 7389 | |
| 7390 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 7391 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 7392 | |
| 7393 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7394 | ssl.next_proto = kProtoHTTP2; |
| 7395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7396 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7397 | ssl2.next_proto = kProtoHTTP2; |
| 7398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7399 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7400 | ssl3.next_proto = kProtoHTTP2; |
| 7401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7402 | |
| 7403 | TestCompletionCallback callback; |
| 7404 | std::string response_data; |
| 7405 | |
| 7406 | // Make a direct HTTP/2 request to proxy:70. |
| 7407 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 7408 | HttpRequestInfo request1; |
| 7409 | request1.method = "GET"; |
| 7410 | request1.url = GURL("https://proxy:70/"); |
| 7411 | request1.traffic_annotation = |
| 7412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7413 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 7414 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 7415 | NetLogWithSource())), |
| 7416 | IsOk()); |
| 7417 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 7418 | RunUntilIdle(); |
| 7419 | |
| 7420 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 7421 | capturing_proxy_resolver.set_proxy_server( |
| 7422 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 7423 | HttpRequestInfo request2; |
| 7424 | request2.method = "GET"; |
| 7425 | request2.url = GURL("https://www.example.org/"); |
| 7426 | request2.traffic_annotation = |
| 7427 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7428 | |
| 7429 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 7430 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 7431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7432 | |
| 7433 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 7434 | base::RunLoop().RunUntilIdle(); |
| 7435 | // Now allow the read of the response to complete. |
| 7436 | spdy_data2.Resume(); |
| 7437 | rv = callback.WaitForResult(); |
| 7438 | EXPECT_THAT(rv, IsOk()); |
| 7439 | |
| 7440 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 7441 | ASSERT_TRUE(response2); |
| 7442 | ASSERT_TRUE(response2->headers); |
| 7443 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 7444 | |
| 7445 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 7446 | EXPECT_EQ(kUploadData, response_data); |
| 7447 | } |
| 7448 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7449 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7450 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7451 | HttpRequestInfo request; |
| 7452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7453 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7454 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7455 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7456 | request.traffic_annotation = |
| 7457 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7458 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7459 | // Configure against https proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7460 | session_deps_.proxy_resolution_service = |
| 7461 | ConfiguredProxyResolutionService::CreateFixed( |
| 7462 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 7463 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7464 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7465 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7466 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7467 | // Since we have proxy, should use full url |
| 7468 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7469 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 7470 | "Host: www.example.org\r\n" |
| 7471 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7473 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7474 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7475 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 7476 | "Host: www.example.org\r\n" |
| 7477 | "Proxy-Connection: keep-alive\r\n" |
| 7478 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7479 | }; |
| 7480 | |
| 7481 | // The proxy responds to the GET with a 407, using a persistent |
| 7482 | // connection. |
| 7483 | MockRead data_reads1[] = { |
| 7484 | // No credentials. |
| 7485 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7486 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7487 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 7488 | MockRead("Content-Length: 0\r\n\r\n"), |
| 7489 | |
| 7490 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7491 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7492 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7493 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7494 | }; |
| 7495 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7496 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7497 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7498 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7501 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7505 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7507 | |
| 7508 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7510 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7511 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7512 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7513 | TestLoadTimingNotReused(load_timing_info, |
| 7514 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7516 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7517 | ASSERT_TRUE(response); |
| 7518 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7519 | EXPECT_EQ(407, response->headers->response_code()); |
| 7520 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7521 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 7522 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7524 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7526 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7527 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7528 | |
| 7529 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7530 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7531 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7532 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7533 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7534 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 7535 | TestLoadTimingReused(load_timing_info); |
| 7536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7537 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7538 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7539 | |
| 7540 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7541 | EXPECT_EQ(200, response->headers->response_code()); |
| 7542 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7543 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 7544 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7545 | |
| 7546 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7547 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7548 | } |
| 7549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7550 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7551 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7552 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7553 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7554 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7555 | request.traffic_annotation = |
| 7556 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7557 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7558 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7559 | session_deps_.proxy_resolution_service = |
| 7560 | ConfiguredProxyResolutionService::CreateFixed( |
| 7561 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7563 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7564 | // Since we have proxy, should try to establish tunnel. |
| 7565 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7566 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7567 | "Host: www.example.org:443\r\n" |
| 7568 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7569 | }; |
| 7570 | |
| 7571 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7572 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 7573 | // No response body because the test stops reading here. |
| 7574 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7575 | }; |
| 7576 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7577 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7578 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7580 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7582 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7583 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7584 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7585 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7586 | |
| 7587 | rv = callback.WaitForResult(); |
| 7588 | EXPECT_EQ(expected_status, rv); |
| 7589 | } |
| 7590 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7591 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7592 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7593 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7594 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7595 | } |
| 7596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7597 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7598 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 7599 | } |
| 7600 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7601 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7602 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 7603 | } |
| 7604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7605 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7606 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 7607 | } |
| 7608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7609 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7610 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 7611 | } |
| 7612 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7613 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7614 | ConnectStatusHelper( |
| 7615 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 7616 | } |
| 7617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7618 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7619 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 7620 | } |
| 7621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7622 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7623 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 7624 | } |
| 7625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7626 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7627 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 7628 | } |
| 7629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7630 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7631 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 7632 | } |
| 7633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7634 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7635 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 7636 | } |
| 7637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7638 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7639 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 7640 | } |
| 7641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7642 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7643 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 7644 | } |
| 7645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7646 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7647 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 7648 | } |
| 7649 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7650 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7651 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 7652 | } |
| 7653 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7654 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7655 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 7656 | } |
| 7657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7658 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7659 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 7660 | } |
| 7661 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7662 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 7663 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 7664 | } |
| 7665 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7666 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7667 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 7668 | } |
| 7669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7670 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7671 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 7672 | } |
| 7673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7674 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7675 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 7676 | } |
| 7677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7678 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7679 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 7680 | } |
| 7681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7682 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7683 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 7684 | } |
| 7685 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7686 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7687 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 7688 | } |
| 7689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7690 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7691 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 7692 | } |
| 7693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7694 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7695 | ConnectStatusHelperWithExpectedStatus( |
| 7696 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 7697 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7698 | } |
| 7699 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7700 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7701 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 7702 | } |
| 7703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7704 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7705 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 7706 | } |
| 7707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7708 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7709 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 7710 | } |
| 7711 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7712 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7713 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 7714 | } |
| 7715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7716 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7717 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 7718 | } |
| 7719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7720 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7721 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 7722 | } |
| 7723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7724 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7725 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 7726 | } |
| 7727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7728 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7729 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 7730 | } |
| 7731 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7732 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7733 | ConnectStatusHelper( |
| 7734 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 7735 | } |
| 7736 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7737 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7738 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 7739 | } |
| 7740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7741 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7742 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 7743 | } |
| 7744 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7745 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7746 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 7747 | } |
| 7748 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7749 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7750 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 7751 | } |
| 7752 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7753 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7754 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 7755 | } |
| 7756 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7757 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7758 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 7759 | } |
| 7760 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7761 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7762 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 7763 | } |
| 7764 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7765 | // Test the flow when both the proxy server AND origin server require |
| 7766 | // authentication. Again, this uses basic auth for both since that is |
| 7767 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7768 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7769 | HttpRequestInfo request; |
| 7770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7771 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7772 | request.traffic_annotation = |
| 7773 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7774 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7775 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7776 | session_deps_.proxy_resolution_service = |
| 7777 | ConfiguredProxyResolutionService::CreateFixed( |
| 7778 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7780 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7782 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7783 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7784 | MockWrite( |
| 7785 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7786 | "Host: www.example.org\r\n" |
| 7787 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7788 | }; |
| 7789 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7790 | MockRead data_reads1[] = { |
| 7791 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7792 | // Give a couple authenticate options (only the middle one is actually |
| 7793 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7794 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7795 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7796 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7797 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7798 | // Large content-length -- won't matter, as connection will be reset. |
| 7799 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7800 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7801 | }; |
| 7802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7803 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7804 | // request we should be issuing -- the final header line contains the |
| 7805 | // proxy's credentials. |
| 7806 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7807 | MockWrite( |
| 7808 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7809 | "Host: www.example.org\r\n" |
| 7810 | "Proxy-Connection: keep-alive\r\n" |
| 7811 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7812 | }; |
| 7813 | |
| 7814 | // Now the proxy server lets the request pass through to origin server. |
| 7815 | // The origin server responds with a 401. |
| 7816 | MockRead data_reads2[] = { |
| 7817 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7818 | // Note: We are using the same realm-name as the proxy server. This is |
| 7819 | // completely valid, as realms are unique across hosts. |
| 7820 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7821 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7822 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7823 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7824 | }; |
| 7825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7826 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7827 | // the credentials for both the proxy and origin server. |
| 7828 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7829 | MockWrite( |
| 7830 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7831 | "Host: www.example.org\r\n" |
| 7832 | "Proxy-Connection: keep-alive\r\n" |
| 7833 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7834 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7835 | }; |
| 7836 | |
| 7837 | // Lastly we get the desired content. |
| 7838 | MockRead data_reads3[] = { |
| 7839 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7840 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7841 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7842 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7843 | }; |
| 7844 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7845 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7846 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7847 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7848 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7849 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7850 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7852 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7853 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7854 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7855 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7856 | |
| 7857 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7858 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7860 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7861 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7862 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7864 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7866 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7868 | |
| 7869 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7870 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7872 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7873 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7874 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7875 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7876 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7877 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7878 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7879 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7881 | |
| 7882 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7883 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7884 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7885 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7886 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7887 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7888 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7889 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7890 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7891 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7892 | // authorization headers. |
| 7893 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7894 | // The NTLM authentication unit tests are based on known test data from the |
| 7895 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7896 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7897 | // for the implementation and testing of the protocol. |
| 7898 | // |
| 7899 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7900 | |
| 7901 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7902 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7903 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7904 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7905 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7906 | request.traffic_annotation = |
| 7907 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7908 | |
| 7909 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7910 | // to other auth schemes. |
| 7911 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7912 | |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 7913 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7914 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7916 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7917 | // Generate the NTLM messages based on known test data. |
| 7918 | std::string negotiate_msg; |
| 7919 | std::string challenge_msg; |
| 7920 | std::string authenticate_msg; |
| 7921 | base::Base64Encode( |
| 7922 | base::StringPiece( |
| 7923 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7924 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7925 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7926 | base::Base64Encode( |
| 7927 | base::StringPiece( |
| 7928 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7929 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7930 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7931 | base::Base64Encode( |
| 7932 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7933 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7934 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7935 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7936 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7937 | &authenticate_msg); |
| 7938 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7939 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7940 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7941 | "Host: server\r\n" |
| 7942 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7943 | }; |
| 7944 | |
| 7945 | MockRead data_reads1[] = { |
| 7946 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7947 | // Negotiate and NTLM are often requested together. However, we only want |
| 7948 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7949 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7950 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7951 | MockRead("Connection: close\r\n"), |
| 7952 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7953 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7954 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7955 | }; |
| 7956 | |
| 7957 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7958 | // After restarting with a null identity, this is the |
| 7959 | // request we should be issuing -- the final header line contains a Type |
| 7960 | // 1 message. |
| 7961 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7962 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7963 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7964 | "Authorization: NTLM "), |
| 7965 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7967 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7968 | // (using correct credentials). The second request continues on the |
| 7969 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7970 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7971 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7972 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7973 | "Authorization: NTLM "), |
| 7974 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7975 | }; |
| 7976 | |
| 7977 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7978 | // The origin server responds with a Type 2 message. |
| 7979 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7980 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7981 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7982 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7983 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7984 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7985 | // Lastly we get the desired content. |
| 7986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7987 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7988 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7989 | }; |
| 7990 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7991 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7992 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7993 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7994 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7995 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7996 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7998 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7999 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 8000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8001 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8002 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8003 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8005 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8007 | |
| 8008 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8009 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8010 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8011 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8013 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8014 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8015 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8017 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8018 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8019 | rv = trans.RestartWithAuth( |
| 8020 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8021 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8023 | |
| 8024 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8025 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8027 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8029 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8030 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8031 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8033 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8035 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8036 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8037 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8038 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8039 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8040 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8041 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8042 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8043 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8044 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 8045 | |
| 8046 | std::string response_data; |
| 8047 | rv = ReadTransaction(&trans, &response_data); |
| 8048 | EXPECT_THAT(rv, IsOk()); |
| 8049 | EXPECT_EQ("Please Login\r\n", response_data); |
| 8050 | |
| 8051 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 8052 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 8053 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 8054 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8055 | } |
| 8056 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8057 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8058 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8059 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8060 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8061 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8062 | request.traffic_annotation = |
| 8063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8064 | |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8065 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8066 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8068 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8069 | // Generate the NTLM messages based on known test data. |
| 8070 | std::string negotiate_msg; |
| 8071 | std::string challenge_msg; |
| 8072 | std::string authenticate_msg; |
| 8073 | base::Base64Encode( |
| 8074 | base::StringPiece( |
| 8075 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8076 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8077 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8078 | base::Base64Encode( |
| 8079 | base::StringPiece( |
| 8080 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8081 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8082 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8083 | base::Base64Encode( |
| 8084 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8085 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8086 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8087 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8088 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8089 | &authenticate_msg); |
| 8090 | |
| 8091 | // The authenticate message when |kWrongPassword| is sent. |
| 8092 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8093 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 8094 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 8095 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 8096 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 8097 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 8098 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8099 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8100 | // Sanity check that it's the same length as the correct authenticate message |
| 8101 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8102 | ASSERT_EQ(authenticate_msg.length(), |
| 8103 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8104 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8105 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8106 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8107 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 8108 | "Host: server\r\n" |
| 8109 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8110 | }; |
| 8111 | |
| 8112 | MockRead data_reads1[] = { |
| 8113 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 8114 | // Negotiate and NTLM are often requested together. However, we only want |
| 8115 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 8116 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8117 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 8118 | MockRead("Connection: close\r\n"), |
| 8119 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 8120 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8121 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8122 | }; |
| 8123 | |
| 8124 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8125 | // After restarting with a null identity, this is the |
| 8126 | // request we should be issuing -- the final header line contains a Type |
| 8127 | // 1 message. |
| 8128 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8129 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8130 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8131 | "Authorization: NTLM "), |
| 8132 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8133 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8134 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8135 | // (using incorrect credentials). The second request continues on the |
| 8136 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8137 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8138 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8139 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8140 | "Authorization: NTLM "), |
| 8141 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8142 | }; |
| 8143 | |
| 8144 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8145 | // The origin server responds with a Type 2 message. |
| 8146 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 8147 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8148 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 8149 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8150 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8151 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8152 | // Wrong password. |
| 8153 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 8154 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 8155 | MockRead("Content-Length: 42\r\n"), |
| 8156 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8157 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8158 | }; |
| 8159 | |
| 8160 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8161 | // After restarting with a null identity, this is the |
| 8162 | // request we should be issuing -- the final header line contains a Type |
| 8163 | // 1 message. |
| 8164 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8165 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8166 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8167 | "Authorization: NTLM "), |
| 8168 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8170 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 8171 | // (the credentials for the origin server). The second request continues |
| 8172 | // on the same connection. |
| 8173 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8174 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8175 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8176 | "Authorization: NTLM "), |
| 8177 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8178 | }; |
| 8179 | |
| 8180 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8181 | // The origin server responds with a Type 2 message. |
| 8182 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8183 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8184 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8185 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8186 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8187 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8188 | // Lastly we get the desired content. |
| 8189 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8190 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 8191 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8192 | }; |
| 8193 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8194 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8195 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8196 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8198 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8199 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8200 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8201 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 8202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8203 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 8204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 8205 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 8206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 8207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8208 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8211 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8212 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8213 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8214 | |
| 8215 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8217 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8218 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8221 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8222 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8224 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8225 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8226 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8227 | rv = trans.RestartWithAuth( |
| 8228 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 8229 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8231 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8232 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8235 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8236 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8237 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8239 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8240 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8241 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8243 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8244 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8245 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8247 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8248 | |
| 8249 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8250 | rv = trans.RestartWithAuth( |
| 8251 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8252 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8254 | |
| 8255 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8256 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8258 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8260 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8261 | |
| 8262 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8263 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8265 | |
| 8266 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8269 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8270 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8271 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 8272 | |
| 8273 | std::string response_data; |
| 8274 | rv = ReadTransaction(&trans, &response_data); |
| 8275 | EXPECT_THAT(rv, IsOk()); |
| 8276 | EXPECT_EQ("Please Login\r\n", response_data); |
| 8277 | |
| 8278 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 8279 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 8280 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 8281 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 8282 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 8283 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8284 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8285 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 8286 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 8287 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8288 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8289 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8290 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8291 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8292 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8293 | |
| 8294 | HttpRequestInfo request; |
| 8295 | request.method = "GET"; |
| 8296 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8297 | request.traffic_annotation = |
| 8298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8299 | |
| 8300 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8301 | spdy::SpdyHeaderBlock request_headers0( |
| 8302 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 8303 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8304 | 1, std::move(request_headers0), LOWEST, true)); |
| 8305 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8306 | spdy::SpdyHeaderBlock response_headers0; |
| 8307 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8308 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8309 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8310 | 1, std::move(response_headers0), true)); |
| 8311 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8312 | // Stream 1 is closed. |
| 8313 | spdy_util_.UpdateWithStreamDestruction(1); |
| 8314 | |
| 8315 | // Generate the NTLM messages based on known test data. |
| 8316 | std::string negotiate_msg; |
| 8317 | std::string challenge_msg; |
| 8318 | std::string authenticate_msg; |
| 8319 | base::Base64Encode( |
| 8320 | base::StringPiece( |
| 8321 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8322 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8323 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8324 | base::Base64Encode( |
| 8325 | base::StringPiece( |
| 8326 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8327 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8328 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8329 | base::Base64Encode( |
| 8330 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8331 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8332 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8333 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8334 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8335 | &authenticate_msg); |
| 8336 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 8337 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 8338 | MockRead reads0[] = {CreateMockRead(resp, 1), |
| 8339 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8340 | |
| 8341 | // Retry yet again using HTTP/1.1. |
| 8342 | MockWrite writes1[] = { |
| 8343 | // After restarting with a null identity, this is the |
| 8344 | // request we should be issuing -- the final header line contains a Type |
| 8345 | // 1 message. |
| 8346 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8347 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8348 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8349 | "Authorization: NTLM "), |
| 8350 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8351 | |
| 8352 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 8353 | // (the credentials for the origin server). The second request continues |
| 8354 | // on the same connection. |
| 8355 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8356 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8357 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8358 | "Authorization: NTLM "), |
| 8359 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8360 | }; |
| 8361 | |
| 8362 | MockRead reads1[] = { |
| 8363 | // The origin server responds with a Type 2 message. |
| 8364 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8365 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8366 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8367 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8368 | MockRead("You are not authorized to view this page\r\n"), |
| 8369 | |
| 8370 | // Lastly we get the desired content. |
| 8371 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8372 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8373 | 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] | 8374 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8375 | SequencedSocketData data0(reads0, writes0); |
| 8376 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8377 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 8378 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8379 | |
| 8380 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 8381 | ssl0.next_proto = kProtoHTTP2; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 8382 | ssl0.next_protos_expected_in_ssl_config = |
| 8383 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8384 | SSLSocketDataProvider ssl1(ASYNC, OK); |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 8385 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 8386 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8387 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 8388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8389 | |
| 8390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8391 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8392 | |
| 8393 | TestCompletionCallback callback1; |
| 8394 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 8395 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8396 | |
| 8397 | rv = callback1.WaitForResult(); |
| 8398 | EXPECT_THAT(rv, IsOk()); |
| 8399 | |
| 8400 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 8401 | |
| 8402 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8403 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8404 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8405 | |
| 8406 | TestCompletionCallback callback2; |
| 8407 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8408 | rv = trans.RestartWithAuth( |
| 8409 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8410 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8412 | |
| 8413 | rv = callback2.WaitForResult(); |
| 8414 | EXPECT_THAT(rv, IsOk()); |
| 8415 | |
| 8416 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 8417 | |
| 8418 | response = trans.GetResponseInfo(); |
| 8419 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8420 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8421 | |
| 8422 | TestCompletionCallback callback3; |
| 8423 | |
| 8424 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 8425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8426 | |
| 8427 | rv = callback3.WaitForResult(); |
| 8428 | EXPECT_THAT(rv, IsOk()); |
| 8429 | |
| 8430 | response = trans.GetResponseInfo(); |
| 8431 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8432 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8433 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 8434 | |
| 8435 | std::string response_data; |
| 8436 | rv = ReadTransaction(&trans, &response_data); |
| 8437 | EXPECT_THAT(rv, IsOk()); |
| 8438 | EXPECT_EQ("Please Login\r\n", response_data); |
| 8439 | |
| 8440 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 8441 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 8442 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 8443 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8444 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8445 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8446 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 8447 | |
| 8448 | // Variant of above test using WebSockets. |
| 8449 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2WithWebsockets) { |
| 8450 | const GURL kInitialUrl("https://server/"); |
| 8451 | const GURL kWebSocketUrl("wss://server/"); |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8452 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8453 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 8454 | |
| 8455 | // Initial request establishes an H2 connection, which will then be reused for |
| 8456 | // WebSockets. This is needed since WebSockets will reuse H2 connections, but |
| 8457 | // it won't create a new one. |
| 8458 | spdy::SpdyHeaderBlock initial_request_headers( |
| 8459 | spdy_util_.ConstructGetHeaderBlock(kInitialUrl.spec())); |
| 8460 | spdy::SpdySerializedFrame initial_request(spdy_util_.ConstructSpdyHeaders( |
| 8461 | 1, std::move(initial_request_headers), DEFAULT_PRIORITY, true)); |
| 8462 | spdy::SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 8463 | |
| 8464 | // Settings frame, indicating WebSockets is supported. |
| 8465 | spdy::SettingsMap settings; |
| 8466 | settings[spdy::SETTINGS_ENABLE_CONNECT_PROTOCOL] = 1; |
| 8467 | spdy::SpdySerializedFrame settings_frame( |
| 8468 | spdy_util_.ConstructSpdySettings(settings)); |
| 8469 | |
| 8470 | // Response headers for first request. Body is never received, but that |
| 8471 | // shouldn't matter for the purposes of this test. |
| 8472 | spdy::SpdySerializedFrame initial_response( |
| 8473 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 8474 | |
| 8475 | // First WebSocket request, which has no credentials. |
| 8476 | spdy::SpdyHeaderBlock websocket_request_headers; |
| 8477 | websocket_request_headers[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 8478 | websocket_request_headers[spdy::kHttp2AuthorityHeader] = "server"; |
| 8479 | websocket_request_headers[spdy::kHttp2SchemeHeader] = "https"; |
| 8480 | websocket_request_headers[spdy::kHttp2PathHeader] = "/"; |
| 8481 | websocket_request_headers[spdy::kHttp2ProtocolHeader] = "websocket"; |
| 8482 | websocket_request_headers["origin"] = "http://server"; |
| 8483 | websocket_request_headers["sec-websocket-version"] = "13"; |
| 8484 | websocket_request_headers["sec-websocket-extensions"] = |
| 8485 | "permessage-deflate; client_max_window_bits"; |
| 8486 | spdy::SpdySerializedFrame websocket_request(spdy_util_.ConstructSpdyHeaders( |
| 8487 | 3, std::move(websocket_request_headers), MEDIUM, false)); |
| 8488 | |
| 8489 | // Auth challenge to WebSocket request. |
| 8490 | spdy::SpdyHeaderBlock auth_challenge_headers; |
| 8491 | auth_challenge_headers[spdy::kHttp2StatusHeader] = "401"; |
| 8492 | auth_challenge_headers["www-authenticate"] = "NTLM"; |
| 8493 | spdy::SpdySerializedFrame websocket_auth_challenge( |
| 8494 | spdy_util_.ConstructSpdyResponseHeaders( |
| 8495 | 3, std::move(auth_challenge_headers), true)); |
| 8496 | |
| 8497 | MockWrite writes0[] = {CreateMockWrite(initial_request, 0), |
| 8498 | CreateMockWrite(settings_ack, 2), |
| 8499 | CreateMockWrite(websocket_request, 4), |
| 8500 | MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 7)}; |
| 8501 | MockRead reads0[] = {CreateMockRead(settings_frame, 1), |
| 8502 | CreateMockRead(initial_response, 3), |
| 8503 | CreateMockRead(websocket_auth_challenge, 5), |
| 8504 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6)}; |
| 8505 | |
| 8506 | // Generate the NTLM messages based on known test data. |
| 8507 | std::string negotiate_msg; |
| 8508 | std::string challenge_msg; |
| 8509 | std::string authenticate_msg; |
| 8510 | base::Base64Encode( |
| 8511 | base::StringPiece( |
| 8512 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 8513 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
| 8514 | &negotiate_msg); |
| 8515 | base::Base64Encode( |
| 8516 | base::StringPiece( |
| 8517 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 8518 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
| 8519 | &challenge_msg); |
| 8520 | base::Base64Encode( |
| 8521 | base::StringPiece( |
| 8522 | reinterpret_cast<const char*>( |
| 8523 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 8524 | base::size( |
| 8525 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 8526 | &authenticate_msg); |
| 8527 | |
| 8528 | // Retry yet again using HTTP/1.1. |
| 8529 | MockWrite writes1[] = { |
| 8530 | // After restarting with a null identity, this is the |
| 8531 | // request we should be issuing -- the final header line contains a Type |
| 8532 | // 1 message. |
| 8533 | MockWrite("GET / HTTP/1.1\r\n" |
| 8534 | "Host: server\r\n" |
| 8535 | "Connection: Upgrade\r\n" |
| 8536 | "Authorization: NTLM "), |
| 8537 | MockWrite(negotiate_msg.c_str()), |
| 8538 | MockWrite("\r\n"), |
| 8539 | MockWrite("Origin: http://server\r\n" |
| 8540 | "Sec-WebSocket-Version: 13\r\n" |
| 8541 | "Upgrade: websocket\r\n" |
| 8542 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 8543 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 8544 | "client_max_window_bits\r\n\r\n"), |
| 8545 | |
| 8546 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 8547 | // (the credentials for the origin server). The second request continues |
| 8548 | // on the same connection. |
| 8549 | MockWrite("GET / HTTP/1.1\r\n" |
| 8550 | "Host: server\r\n" |
| 8551 | "Connection: Upgrade\r\n" |
| 8552 | "Authorization: NTLM "), |
| 8553 | MockWrite(authenticate_msg.c_str()), |
| 8554 | MockWrite("\r\n"), |
| 8555 | MockWrite("Origin: http://server\r\n" |
| 8556 | "Sec-WebSocket-Version: 13\r\n" |
| 8557 | "Upgrade: websocket\r\n" |
| 8558 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 8559 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 8560 | "client_max_window_bits\r\n\r\n"), |
| 8561 | }; |
| 8562 | |
| 8563 | MockRead reads1[] = { |
| 8564 | // The origin server responds with a Type 2 message. |
| 8565 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 8566 | MockRead("WWW-Authenticate: NTLM "), |
| 8567 | MockRead(challenge_msg.c_str()), |
| 8568 | MockRead("\r\n"), |
| 8569 | MockRead("Content-Length: 42\r\n"), |
| 8570 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8571 | MockRead("You are not authorized to view this page\r\n"), |
| 8572 | |
| 8573 | // Lastly we get the desired content. |
| 8574 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 8575 | "Upgrade: websocket\r\n" |
| 8576 | "Connection: Upgrade\r\n" |
| 8577 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 8578 | }; |
| 8579 | SequencedSocketData data0(reads0, writes0); |
| 8580 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 8581 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 8582 | ssl0.next_proto = kProtoHTTP2; |
| 8583 | ssl0.next_protos_expected_in_ssl_config = |
| 8584 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
| 8585 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 8586 | |
| 8587 | StaticSocketDataProvider data1(reads1, writes1); |
| 8588 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8589 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 8590 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 8591 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{}; |
| 8592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8593 | |
| 8594 | session_deps_.enable_websocket_over_http2 = true; |
| 8595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8596 | |
| 8597 | HttpRequestInfo initial_request_info; |
| 8598 | initial_request_info.method = "GET"; |
| 8599 | initial_request_info.url = kInitialUrl; |
| 8600 | initial_request_info.traffic_annotation = |
| 8601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8602 | HttpNetworkTransaction initial_trans(DEFAULT_PRIORITY, session.get()); |
| 8603 | TestCompletionCallback initial_callback; |
| 8604 | int rv = initial_trans.Start(&initial_request_info, |
| 8605 | initial_callback.callback(), NetLogWithSource()); |
| 8606 | EXPECT_THAT(initial_callback.GetResult(rv), IsOk()); |
| 8607 | |
| 8608 | EXPECT_FALSE(session->http_server_properties()->RequiresHTTP11( |
| 8609 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 8610 | |
| 8611 | HttpRequestInfo websocket_request_info; |
| 8612 | websocket_request_info.method = "GET"; |
| 8613 | websocket_request_info.url = kWebSocketUrl; |
| 8614 | websocket_request_info.traffic_annotation = |
| 8615 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8616 | EXPECT_TRUE(HostPortPair::FromURL(initial_request_info.url) |
| 8617 | .Equals(HostPortPair::FromURL(websocket_request_info.url))); |
| 8618 | websocket_request_info.extra_headers.SetHeader("Origin", "http://server"); |
| 8619 | websocket_request_info.extra_headers.SetHeader("Sec-WebSocket-Version", "13"); |
| 8620 | // The following two headers must be removed by WebSocketHttp2HandshakeStream. |
| 8621 | websocket_request_info.extra_headers.SetHeader("Connection", "Upgrade"); |
| 8622 | websocket_request_info.extra_headers.SetHeader("Upgrade", "websocket"); |
| 8623 | |
| 8624 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 8625 | |
| 8626 | HttpNetworkTransaction websocket_trans(MEDIUM, session.get()); |
| 8627 | websocket_trans.SetWebSocketHandshakeStreamCreateHelper( |
| 8628 | &websocket_stream_create_helper); |
| 8629 | |
| 8630 | TestCompletionCallback websocket_callback; |
| 8631 | rv = websocket_trans.Start(&websocket_request_info, |
| 8632 | websocket_callback.callback(), NetLogWithSource()); |
| 8633 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8634 | |
| 8635 | EXPECT_FALSE(websocket_trans.IsReadyToRestartForAuth()); |
| 8636 | |
| 8637 | const HttpResponseInfo* response = websocket_trans.GetResponseInfo(); |
| 8638 | ASSERT_TRUE(response); |
| 8639 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
| 8640 | |
| 8641 | rv = websocket_trans.RestartWithAuth( |
| 8642 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8643 | websocket_callback.callback()); |
| 8644 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8645 | |
| 8646 | EXPECT_TRUE(websocket_trans.IsReadyToRestartForAuth()); |
| 8647 | |
| 8648 | response = websocket_trans.GetResponseInfo(); |
| 8649 | ASSERT_TRUE(response); |
| 8650 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 8651 | |
| 8652 | rv = websocket_trans.RestartWithAuth(AuthCredentials(), |
| 8653 | websocket_callback.callback()); |
| 8654 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8655 | |
| 8656 | // The server should have been marked as requiring HTTP/1.1. The important |
| 8657 | // part here is that the scheme that requires HTTP/1.1 should be HTTPS, not |
| 8658 | // WSS. |
| 8659 | EXPECT_TRUE(session->http_server_properties()->RequiresHTTP11( |
| 8660 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 8661 | } |
| 8662 | |
| 8663 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 8664 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8665 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 8666 | // do no retry forever as a result of TLS retries. This is a regression test for |
| 8667 | // https://crbug.com/823387. The version interference probe has since been |
| 8668 | // removed, but we now have a legacy crypto fallback. (If that fallback is |
| 8669 | // removed, this test should be kept but with the expectations tweaked, in case |
| 8670 | // future fallbacks are added.) |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8671 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 8672 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 8673 | // https://origin/. |
| 8674 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 8675 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8676 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8677 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 8678 | SSLContextConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8679 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 8680 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8681 | |
| 8682 | HttpRequestInfo request; |
| 8683 | request.method = "GET"; |
| 8684 | request.url = GURL("https://origin/"); |
| 8685 | request.traffic_annotation = |
| 8686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8687 | |
| 8688 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 8689 | // to other auth schemes. |
| 8690 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 8691 | |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8692 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8693 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 8694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8695 | |
| 8696 | // Generate the NTLM messages based on known test data. |
| 8697 | std::string negotiate_msg; |
| 8698 | std::string challenge_msg; |
| 8699 | std::string authenticate_msg; |
| 8700 | base::Base64Encode( |
| 8701 | base::StringPiece( |
| 8702 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8703 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8704 | &negotiate_msg); |
| 8705 | base::Base64Encode( |
| 8706 | base::StringPiece( |
| 8707 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8708 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8709 | &challenge_msg); |
| 8710 | base::Base64Encode( |
| 8711 | base::StringPiece( |
| 8712 | reinterpret_cast<const char*>( |
| 8713 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8714 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8715 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 8716 | &authenticate_msg); |
| 8717 | |
| 8718 | MockWrite data_writes[] = { |
| 8719 | // The initial CONNECT request. |
| 8720 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8721 | "Host: origin:443\r\n" |
| 8722 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8723 | |
| 8724 | // After restarting with an identity. |
| 8725 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8726 | "Host: origin:443\r\n" |
| 8727 | "Proxy-Connection: keep-alive\r\n" |
| 8728 | "Proxy-Authorization: NTLM "), |
| 8729 | MockWrite(negotiate_msg.c_str()), |
| 8730 | // End headers. |
| 8731 | MockWrite("\r\n\r\n"), |
| 8732 | |
| 8733 | // The second restart. |
| 8734 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8735 | "Host: origin:443\r\n" |
| 8736 | "Proxy-Connection: keep-alive\r\n" |
| 8737 | "Proxy-Authorization: NTLM "), |
| 8738 | MockWrite(authenticate_msg.c_str()), |
| 8739 | // End headers. |
| 8740 | MockWrite("\r\n\r\n"), |
| 8741 | }; |
| 8742 | |
| 8743 | MockRead data_reads[] = { |
| 8744 | // The initial NTLM response. |
| 8745 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 8746 | "Content-Length: 0\r\n" |
| 8747 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 8748 | |
| 8749 | // The NTLM challenge message. |
| 8750 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 8751 | "Content-Length: 0\r\n" |
| 8752 | "Proxy-Authenticate: NTLM "), |
| 8753 | MockRead(challenge_msg.c_str()), |
| 8754 | // End headers. |
| 8755 | MockRead("\r\n\r\n"), |
| 8756 | |
| 8757 | // Finally the tunnel is established. |
| 8758 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 8759 | }; |
| 8760 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8761 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8762 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8765 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 8766 | StaticSocketDataProvider data2(data_reads, data_writes); |
| 8767 | SSLSocketDataProvider data2_ssl(ASYNC, ERR_CONNECTION_RESET); |
| 8768 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data2_ssl); |
| 8770 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8771 | // Start the transaction. The proxy responds with an NTLM authentication |
| 8772 | // request. |
| 8773 | TestCompletionCallback callback; |
| 8774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8775 | int rv = callback.GetResult( |
| 8776 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 8777 | |
| 8778 | EXPECT_THAT(rv, IsOk()); |
| 8779 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 8780 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8781 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8782 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8783 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 8784 | // Configure credentials and restart. The proxy responds with the challenge |
| 8785 | // message. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8786 | rv = callback.GetResult(trans.RestartWithAuth( |
| 8787 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8788 | callback.callback())); |
| 8789 | EXPECT_THAT(rv, IsOk()); |
| 8790 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 8791 | response = trans.GetResponseInfo(); |
| 8792 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8793 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8794 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 8795 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 8796 | // will reset. The fallback will then kick in and restart the process. The |
| 8797 | // proxy responds with another NTLM authentiation request, but we don't need |
| 8798 | // to provide credentials as the cached ones work. |
| 8799 | rv = callback.GetResult( |
| 8800 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 8801 | EXPECT_THAT(rv, IsOk()); |
| 8802 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 8803 | response = trans.GetResponseInfo(); |
| 8804 | ASSERT_TRUE(response); |
| 8805 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 8806 | |
| 8807 | // The proxy responds with the NTLM challenge message. |
| 8808 | rv = callback.GetResult( |
| 8809 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 8810 | EXPECT_THAT(rv, IsOk()); |
| 8811 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 8812 | response = trans.GetResponseInfo(); |
| 8813 | ASSERT_TRUE(response); |
| 8814 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 8815 | |
| 8816 | // Send the NTLM authenticate message. The tunnel is established and the |
| 8817 | // handshake resets again. We should not retry again. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8818 | rv = callback.GetResult( |
| 8819 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 8820 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 8821 | } |
| 8822 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8823 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8824 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8825 | // Test reading a server response which has only headers, and no body. |
| 8826 | // After some maximum number of bytes is consumed, the transaction should |
| 8827 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8828 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8829 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8831 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8832 | request.traffic_annotation = |
| 8833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8834 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8835 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8836 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8837 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 8838 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 8839 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 8840 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8841 | |
| 8842 | MockRead data_reads[] = { |
| 8843 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8844 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8845 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8847 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8848 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8851 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8852 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8853 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8855 | |
| 8856 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8857 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8858 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8859 | |
| 8860 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 8861 | // establish tunnel. |
| 8862 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8863 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8864 | HttpRequestInfo request; |
| 8865 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8866 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8867 | request.traffic_annotation = |
| 8868 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8869 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8870 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 8871 | session_deps_.proxy_resolution_service = |
| 8872 | ConfiguredProxyResolutionService::CreateFixed( |
| 8873 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 8874 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8876 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8877 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8878 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8879 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8880 | // Since we have proxy, should try to establish tunnel. |
| 8881 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8882 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8883 | "Host: www.example.org:443\r\n" |
| 8884 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8885 | }; |
| 8886 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 8887 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8888 | // connection. Usually a proxy would return 501 (not implemented), |
| 8889 | // or 200 (tunnel established). |
| 8890 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 8891 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8892 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8893 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8894 | }; |
| 8895 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8896 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8897 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8899 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8900 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8901 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8903 | |
| 8904 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8905 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8906 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8907 | // Empty the current queue. This is necessary because idle sockets are |
| 8908 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8909 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8910 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8911 | // We now check to make sure the TCPClientSocket was not added back to |
| 8912 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8913 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8914 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8915 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8916 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8917 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8918 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8919 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8920 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8921 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8922 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8923 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8924 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8925 | request.traffic_annotation = |
| 8926 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8927 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8930 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8931 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8932 | MockRead data_reads[] = { |
| 8933 | // A part of the response body is received with the response headers. |
| 8934 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8935 | // The rest of the response body is received in two parts. |
| 8936 | MockRead("lo"), |
| 8937 | MockRead(" world"), |
| 8938 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8939 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8940 | }; |
| 8941 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8942 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8943 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8945 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8947 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8949 | |
| 8950 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8951 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8953 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8954 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8955 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8956 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8957 | std::string status_line = response->headers->GetStatusLine(); |
| 8958 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8959 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8960 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8961 | |
| 8962 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8963 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8964 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8965 | EXPECT_EQ("hello world", response_data); |
| 8966 | |
| 8967 | // Empty the current queue. This is necessary because idle sockets are |
| 8968 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8969 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8970 | |
| 8971 | // 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] | 8972 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8973 | } |
| 8974 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8975 | // Make sure that we recycle a SSL socket after reading all of the response |
| 8976 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8977 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8978 | HttpRequestInfo request; |
| 8979 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8980 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8981 | request.traffic_annotation = |
| 8982 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8983 | |
| 8984 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8985 | MockWrite( |
| 8986 | "GET / HTTP/1.1\r\n" |
| 8987 | "Host: www.example.org\r\n" |
| 8988 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8989 | }; |
| 8990 | |
| 8991 | MockRead data_reads[] = { |
| 8992 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8993 | MockRead("Content-Length: 11\r\n\r\n"), |
| 8994 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8995 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8996 | }; |
| 8997 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8998 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8999 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9000 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9001 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9002 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9004 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9005 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9007 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9008 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9009 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9010 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9011 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9012 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9014 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9015 | ASSERT_TRUE(response); |
| 9016 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9017 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9018 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9019 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9020 | |
| 9021 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9022 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9024 | EXPECT_EQ("hello world", response_data); |
| 9025 | |
| 9026 | // Empty the current queue. This is necessary because idle sockets are |
| 9027 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9028 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9029 | |
| 9030 | // 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] | 9031 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9032 | } |
| 9033 | |
| 9034 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 9035 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9036 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9037 | HttpRequestInfo request; |
| 9038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9039 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9040 | request.traffic_annotation = |
| 9041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9042 | |
| 9043 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9044 | MockWrite( |
| 9045 | "GET / HTTP/1.1\r\n" |
| 9046 | "Host: www.example.org\r\n" |
| 9047 | "Connection: keep-alive\r\n\r\n"), |
| 9048 | MockWrite( |
| 9049 | "GET / HTTP/1.1\r\n" |
| 9050 | "Host: www.example.org\r\n" |
| 9051 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9052 | }; |
| 9053 | |
| 9054 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 9055 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 9056 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9057 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9058 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 9059 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9062 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9063 | StaticSocketDataProvider data(data_reads, data_writes); |
| 9064 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9065 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9066 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9068 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9071 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9072 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9073 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9074 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9075 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9077 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9078 | |
| 9079 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9080 | ASSERT_TRUE(response); |
| 9081 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9082 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9083 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9084 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9085 | |
| 9086 | std::string response_data; |
| 9087 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9088 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9089 | EXPECT_EQ("hello world", response_data); |
| 9090 | |
| 9091 | // Empty the current queue. This is necessary because idle sockets are |
| 9092 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9093 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9094 | |
| 9095 | // 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] | 9096 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9097 | |
| 9098 | // Now start the second transaction, which should reuse the previous socket. |
| 9099 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9100 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9101 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9102 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9103 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9104 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9106 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9107 | |
| 9108 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9109 | ASSERT_TRUE(response); |
| 9110 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9111 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9112 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9113 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9114 | |
| 9115 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9117 | EXPECT_EQ("hello world", response_data); |
| 9118 | |
| 9119 | // Empty the current queue. This is necessary because idle sockets are |
| 9120 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9121 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9122 | |
| 9123 | // 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] | 9124 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9125 | } |
| 9126 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9127 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 9128 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9129 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9130 | HttpRequestInfo request; |
| 9131 | request.method = "GET"; |
| 9132 | request.url = GURL("http://www.example.org/"); |
| 9133 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9134 | request.traffic_annotation = |
| 9135 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9136 | |
| 9137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9140 | |
| 9141 | MockRead data_reads[] = { |
| 9142 | // A part of the response body is received with the response headers. |
| 9143 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 9144 | // The rest of the response body is received in two parts. |
| 9145 | MockRead("lo"), MockRead(" world"), |
| 9146 | MockRead("junk"), // Should not be read!! |
| 9147 | MockRead(SYNCHRONOUS, OK), |
| 9148 | }; |
| 9149 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9150 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9152 | |
| 9153 | TestCompletionCallback callback; |
| 9154 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9155 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9157 | |
| 9158 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 9159 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9160 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9161 | ASSERT_TRUE(response); |
| 9162 | EXPECT_TRUE(response->headers); |
| 9163 | std::string status_line = response->headers->GetStatusLine(); |
| 9164 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 9165 | |
| 9166 | // Make memory critical notification and ensure the transaction still has been |
| 9167 | // operating right. |
| 9168 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9169 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9170 | base::RunLoop().RunUntilIdle(); |
| 9171 | |
| 9172 | // Socket should not be flushed as long as it is not idle. |
| 9173 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9174 | |
| 9175 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9176 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9177 | EXPECT_THAT(rv, IsOk()); |
| 9178 | EXPECT_EQ("hello world", response_data); |
| 9179 | |
| 9180 | // Empty the current queue. This is necessary because idle sockets are |
| 9181 | // added to the connection pool asynchronously with a PostTask. |
| 9182 | base::RunLoop().RunUntilIdle(); |
| 9183 | |
| 9184 | // We now check to make sure the socket was added back to the pool. |
| 9185 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9186 | |
| 9187 | // Idle sockets should be flushed now. |
| 9188 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9189 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9190 | base::RunLoop().RunUntilIdle(); |
| 9191 | |
| 9192 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9193 | } |
| 9194 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 9195 | // Disable idle socket closing on memory pressure. |
| 9196 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 9197 | // low memory notification and ensure the socket pool is NOT flushed. |
| 9198 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 9199 | HttpRequestInfo request; |
| 9200 | request.method = "GET"; |
| 9201 | request.url = GURL("http://www.example.org/"); |
| 9202 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9203 | request.traffic_annotation = |
| 9204 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 9205 | |
| 9206 | // Disable idle socket closing on memory pressure. |
| 9207 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 9208 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9209 | |
| 9210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9211 | |
| 9212 | MockRead data_reads[] = { |
| 9213 | // A part of the response body is received with the response headers. |
| 9214 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 9215 | // The rest of the response body is received in two parts. |
| 9216 | MockRead("lo"), MockRead(" world"), |
| 9217 | MockRead("junk"), // Should not be read!! |
| 9218 | MockRead(SYNCHRONOUS, OK), |
| 9219 | }; |
| 9220 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9221 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 9222 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9223 | |
| 9224 | TestCompletionCallback callback; |
| 9225 | |
| 9226 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9228 | |
| 9229 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 9230 | |
| 9231 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 9232 | ASSERT_TRUE(response); |
| 9233 | EXPECT_TRUE(response->headers); |
| 9234 | std::string status_line = response->headers->GetStatusLine(); |
| 9235 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 9236 | |
| 9237 | // Make memory critical notification and ensure the transaction still has been |
| 9238 | // operating right. |
| 9239 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9240 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9241 | base::RunLoop().RunUntilIdle(); |
| 9242 | |
| 9243 | // Socket should not be flushed as long as it is not idle. |
| 9244 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9245 | |
| 9246 | std::string response_data; |
| 9247 | rv = ReadTransaction(&trans, &response_data); |
| 9248 | EXPECT_THAT(rv, IsOk()); |
| 9249 | EXPECT_EQ("hello world", response_data); |
| 9250 | |
| 9251 | // Empty the current queue. This is necessary because idle sockets are |
| 9252 | // added to the connection pool asynchronously with a PostTask. |
| 9253 | base::RunLoop().RunUntilIdle(); |
| 9254 | |
| 9255 | // We now check to make sure the socket was added back to the pool. |
| 9256 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9257 | |
| 9258 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 9259 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9260 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 9261 | base::RunLoop().RunUntilIdle(); |
| 9262 | |
| 9263 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9264 | |
| 9265 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 9266 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9267 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9268 | base::RunLoop().RunUntilIdle(); |
| 9269 | |
| 9270 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9271 | } |
| 9272 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9273 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 9274 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9275 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9276 | HttpRequestInfo request; |
| 9277 | request.method = "GET"; |
| 9278 | request.url = GURL("https://www.example.org/"); |
| 9279 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9280 | request.traffic_annotation = |
| 9281 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9282 | |
| 9283 | MockWrite data_writes[] = { |
| 9284 | MockWrite("GET / HTTP/1.1\r\n" |
| 9285 | "Host: www.example.org\r\n" |
| 9286 | "Connection: keep-alive\r\n\r\n"), |
| 9287 | }; |
| 9288 | |
| 9289 | MockRead data_reads[] = { |
| 9290 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 9291 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 9292 | |
| 9293 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 9294 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9295 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9296 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9297 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9298 | |
| 9299 | TestCompletionCallback callback; |
| 9300 | |
| 9301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9303 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 9304 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9305 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9306 | |
| 9307 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 9308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9309 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9310 | ASSERT_TRUE(response); |
| 9311 | ASSERT_TRUE(response->headers); |
| 9312 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9313 | |
| 9314 | // Make memory critical notification and ensure the transaction still has been |
| 9315 | // operating right. |
| 9316 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9317 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9318 | base::RunLoop().RunUntilIdle(); |
| 9319 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 9320 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9321 | |
| 9322 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9323 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9324 | EXPECT_THAT(rv, IsOk()); |
| 9325 | EXPECT_EQ("hello world", response_data); |
| 9326 | |
| 9327 | // Empty the current queue. This is necessary because idle sockets are |
| 9328 | // added to the connection pool asynchronously with a PostTask. |
| 9329 | base::RunLoop().RunUntilIdle(); |
| 9330 | |
| 9331 | // 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] | 9332 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9333 | |
| 9334 | // Make memory notification once again and ensure idle socket is closed. |
| 9335 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9336 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9337 | base::RunLoop().RunUntilIdle(); |
| 9338 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 9339 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9340 | } |
| 9341 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9342 | // Make sure that we recycle a socket after a zero-length response. |
| 9343 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9344 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9345 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9346 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9347 | request.url = GURL( |
| 9348 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 9349 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 9350 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 9351 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9352 | request.traffic_annotation = |
| 9353 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9356 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9357 | MockRead data_reads[] = { |
| 9358 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 9359 | "Content-Length: 0\r\n" |
| 9360 | "Content-Type: text/html\r\n\r\n"), |
| 9361 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9362 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9363 | }; |
| 9364 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9365 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9367 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 9368 | // Transaction must be created after the MockReads, so it's destroyed before |
| 9369 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 9371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9372 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9373 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9374 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9376 | |
| 9377 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9378 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9379 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9380 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9381 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9382 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9383 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9384 | std::string status_line = response->headers->GetStatusLine(); |
| 9385 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 9386 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9387 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9388 | |
| 9389 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9390 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9392 | EXPECT_EQ("", response_data); |
| 9393 | |
| 9394 | // Empty the current queue. This is necessary because idle sockets are |
| 9395 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9396 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9397 | |
| 9398 | // 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] | 9399 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9400 | } |
| 9401 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9402 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9403 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9404 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9405 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9406 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9407 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9408 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9409 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 9410 | // after use. |
| 9411 | request[0].method = "GET"; |
| 9412 | request[0].url = GURL("http://www.google.com/"); |
| 9413 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9414 | request[0].traffic_annotation = |
| 9415 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9416 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 9417 | // transaction 1. The first attempts fails when writing the POST data. |
| 9418 | // This causes the transaction to retry with a new socket. The second |
| 9419 | // attempt succeeds. |
| 9420 | request[1].method = "POST"; |
| 9421 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9422 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9423 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9424 | request[1].traffic_annotation = |
| 9425 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9428 | |
| 9429 | // The first socket is used for transaction 1 and the first attempt of |
| 9430 | // transaction 2. |
| 9431 | |
| 9432 | // The response of transaction 1. |
| 9433 | MockRead data_reads1[] = { |
| 9434 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 9435 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9436 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9437 | }; |
| 9438 | // The mock write results of transaction 1 and the first attempt of |
| 9439 | // transaction 2. |
| 9440 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9441 | MockWrite(SYNCHRONOUS, 64), // GET |
| 9442 | MockWrite(SYNCHRONOUS, 93), // POST |
| 9443 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9444 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9445 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9446 | |
| 9447 | // The second socket is used for the second attempt of transaction 2. |
| 9448 | |
| 9449 | // The response of transaction 2. |
| 9450 | MockRead data_reads2[] = { |
| 9451 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 9452 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9453 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9454 | }; |
| 9455 | // The mock write results of the second attempt of transaction 2. |
| 9456 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9457 | MockWrite(SYNCHRONOUS, 93), // POST |
| 9458 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9459 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9460 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9461 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9462 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9463 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9464 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9465 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9466 | "hello world", "welcome" |
| 9467 | }; |
| 9468 | |
| 9469 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9472 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9474 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9476 | |
| 9477 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9480 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9481 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9482 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9483 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9484 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9485 | |
| 9486 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9487 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9489 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 9490 | } |
| 9491 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9492 | |
| 9493 | // Test the request-challenge-retry sequence for basic auth when there is |
| 9494 | // 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] | 9495 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9496 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9497 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9498 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9499 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 9500 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9501 | request.traffic_annotation = |
| 9502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 9503 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9506 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 9507 | // The password contains an escaped character -- for this test to pass it |
| 9508 | // will need to be unescaped by HttpNetworkTransaction. |
| 9509 | EXPECT_EQ("b%40r", request.url.password()); |
| 9510 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9511 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9512 | MockWrite( |
| 9513 | "GET / HTTP/1.1\r\n" |
| 9514 | "Host: www.example.org\r\n" |
| 9515 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9516 | }; |
| 9517 | |
| 9518 | MockRead data_reads1[] = { |
| 9519 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9520 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9521 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9522 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9523 | }; |
| 9524 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9525 | // After the challenge above, the transaction will be restarted using the |
| 9526 | // identity from the url (foo, b@r) to answer the challenge. |
| 9527 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9528 | MockWrite( |
| 9529 | "GET / HTTP/1.1\r\n" |
| 9530 | "Host: www.example.org\r\n" |
| 9531 | "Connection: keep-alive\r\n" |
| 9532 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9533 | }; |
| 9534 | |
| 9535 | MockRead data_reads2[] = { |
| 9536 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9537 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9538 | MockRead(SYNCHRONOUS, OK), |
| 9539 | }; |
| 9540 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9541 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9542 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9543 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9544 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9545 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9546 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9547 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9548 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9549 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9550 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9551 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9552 | |
| 9553 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9554 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9556 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9557 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9558 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9560 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9561 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9562 | |
| 9563 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9564 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9565 | |
| 9566 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9567 | |
| 9568 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9569 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9570 | } |
| 9571 | |
| 9572 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 9573 | // incorrect identity in the URL. The identity from the URL should be used only |
| 9574 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9575 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9576 | HttpRequestInfo request; |
| 9577 | request.method = "GET"; |
| 9578 | // Note: the URL has a username:password in it. The password "baz" is |
| 9579 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9580 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9581 | |
| 9582 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9583 | request.traffic_annotation = |
| 9584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9585 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9588 | |
| 9589 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9590 | MockWrite( |
| 9591 | "GET / HTTP/1.1\r\n" |
| 9592 | "Host: www.example.org\r\n" |
| 9593 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9594 | }; |
| 9595 | |
| 9596 | MockRead data_reads1[] = { |
| 9597 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9598 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9599 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9600 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9601 | }; |
| 9602 | |
| 9603 | // After the challenge above, the transaction will be restarted using the |
| 9604 | // identity from the url (foo, baz) to answer the challenge. |
| 9605 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9606 | MockWrite( |
| 9607 | "GET / HTTP/1.1\r\n" |
| 9608 | "Host: www.example.org\r\n" |
| 9609 | "Connection: keep-alive\r\n" |
| 9610 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9611 | }; |
| 9612 | |
| 9613 | MockRead data_reads2[] = { |
| 9614 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9615 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9616 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9617 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9618 | }; |
| 9619 | |
| 9620 | // After the challenge above, the transaction will be restarted using the |
| 9621 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 9622 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9623 | MockWrite( |
| 9624 | "GET / HTTP/1.1\r\n" |
| 9625 | "Host: www.example.org\r\n" |
| 9626 | "Connection: keep-alive\r\n" |
| 9627 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9628 | }; |
| 9629 | |
| 9630 | MockRead data_reads3[] = { |
| 9631 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9632 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9633 | MockRead(SYNCHRONOUS, OK), |
| 9634 | }; |
| 9635 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9636 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9637 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9638 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9639 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9640 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9641 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9642 | |
| 9643 | TestCompletionCallback callback1; |
| 9644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9645 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9647 | |
| 9648 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9649 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9651 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9652 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9653 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9655 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9656 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9657 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9659 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9660 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9661 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9662 | |
| 9663 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9664 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9666 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9667 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9668 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9670 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9671 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9672 | |
| 9673 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9674 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9675 | |
| 9676 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9677 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 9678 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9679 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 9680 | } |
| 9681 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9682 | |
| 9683 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 9684 | // correct identity in the URL, but its use is being suppressed. The identity |
| 9685 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9686 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9687 | HttpRequestInfo request; |
| 9688 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9689 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9690 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9691 | request.traffic_annotation = |
| 9692 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9693 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9696 | |
| 9697 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9698 | MockWrite( |
| 9699 | "GET / HTTP/1.1\r\n" |
| 9700 | "Host: www.example.org\r\n" |
| 9701 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9702 | }; |
| 9703 | |
| 9704 | MockRead data_reads1[] = { |
| 9705 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9706 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9707 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9708 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9709 | }; |
| 9710 | |
| 9711 | // After the challenge above, the transaction will be restarted using the |
| 9712 | // identity supplied by the user, not the one in the URL, to answer the |
| 9713 | // challenge. |
| 9714 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9715 | MockWrite( |
| 9716 | "GET / HTTP/1.1\r\n" |
| 9717 | "Host: www.example.org\r\n" |
| 9718 | "Connection: keep-alive\r\n" |
| 9719 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9720 | }; |
| 9721 | |
| 9722 | MockRead data_reads3[] = { |
| 9723 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9724 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9725 | MockRead(SYNCHRONOUS, OK), |
| 9726 | }; |
| 9727 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9728 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9729 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9730 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9731 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9732 | |
| 9733 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9734 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9736 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9737 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9738 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9740 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9741 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9742 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9743 | |
| 9744 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9745 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9747 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9748 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9749 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9751 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9752 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9753 | |
| 9754 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9755 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9756 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9757 | |
| 9758 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9759 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9760 | } |
| 9761 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9762 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9763 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9765 | |
| 9766 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9767 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9768 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9770 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9771 | request.traffic_annotation = |
| 9772 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9775 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9776 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9777 | MockWrite( |
| 9778 | "GET /x/y/z HTTP/1.1\r\n" |
| 9779 | "Host: www.example.org\r\n" |
| 9780 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9781 | }; |
| 9782 | |
| 9783 | MockRead data_reads1[] = { |
| 9784 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9785 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9786 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9787 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9788 | }; |
| 9789 | |
| 9790 | // Resend with authorization (username=foo, password=bar) |
| 9791 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9792 | MockWrite( |
| 9793 | "GET /x/y/z HTTP/1.1\r\n" |
| 9794 | "Host: www.example.org\r\n" |
| 9795 | "Connection: keep-alive\r\n" |
| 9796 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9797 | }; |
| 9798 | |
| 9799 | // Sever accepts the authorization. |
| 9800 | MockRead data_reads2[] = { |
| 9801 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9802 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9804 | }; |
| 9805 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9806 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9807 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9808 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9809 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9811 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9813 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9815 | |
| 9816 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9817 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9819 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9820 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9821 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9823 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9825 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9826 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9828 | |
| 9829 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9832 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9833 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9834 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9835 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9836 | } |
| 9837 | |
| 9838 | // ------------------------------------------------------------------------ |
| 9839 | |
| 9840 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 9841 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9842 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9843 | request.method = "GET"; |
| 9844 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9845 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9846 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9847 | request.traffic_annotation = |
| 9848 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9850 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9851 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9852 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9853 | MockWrite( |
| 9854 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9855 | "Host: www.example.org\r\n" |
| 9856 | "Connection: keep-alive\r\n" |
| 9857 | // Send preemptive authorization for MyRealm1 |
| 9858 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9859 | }; |
| 9860 | |
| 9861 | // The server didn't like the preemptive authorization, and |
| 9862 | // challenges us for a different realm (MyRealm2). |
| 9863 | MockRead data_reads1[] = { |
| 9864 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9865 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 9866 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9867 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9868 | }; |
| 9869 | |
| 9870 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 9871 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9872 | MockWrite( |
| 9873 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9874 | "Host: www.example.org\r\n" |
| 9875 | "Connection: keep-alive\r\n" |
| 9876 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9877 | }; |
| 9878 | |
| 9879 | // Sever accepts the authorization. |
| 9880 | MockRead data_reads2[] = { |
| 9881 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9882 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9883 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9884 | }; |
| 9885 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9886 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9887 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9888 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9889 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9890 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9891 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9892 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9893 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9895 | |
| 9896 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9897 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9899 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9900 | ASSERT_TRUE(response); |
| 9901 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9902 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9903 | EXPECT_EQ("http://www.example.org", |
| 9904 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9905 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9906 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9907 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9908 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9910 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 9911 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9913 | |
| 9914 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9915 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9917 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9918 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9919 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9920 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9921 | } |
| 9922 | |
| 9923 | // ------------------------------------------------------------------------ |
| 9924 | |
| 9925 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 9926 | // succeed with preemptive authorization. |
| 9927 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9928 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9930 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9931 | request.traffic_annotation = |
| 9932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9934 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9935 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9936 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9937 | MockWrite( |
| 9938 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 9939 | "Host: www.example.org\r\n" |
| 9940 | "Connection: keep-alive\r\n" |
| 9941 | // The authorization for MyRealm1 gets sent preemptively |
| 9942 | // (since the url is in the same protection space) |
| 9943 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9944 | }; |
| 9945 | |
| 9946 | // Sever accepts the preemptive authorization |
| 9947 | MockRead data_reads1[] = { |
| 9948 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9949 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9950 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9951 | }; |
| 9952 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9953 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9954 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9956 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9958 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9960 | |
| 9961 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9964 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9965 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9966 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9967 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9968 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9969 | } |
| 9970 | |
| 9971 | // ------------------------------------------------------------------------ |
| 9972 | |
| 9973 | // Transaction 4: request another URL in MyRealm (however the |
| 9974 | // url is not known to belong to the protection space, so no pre-auth). |
| 9975 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9976 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9978 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9979 | request.traffic_annotation = |
| 9980 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9981 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9982 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9983 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9984 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9985 | MockWrite( |
| 9986 | "GET /x/1 HTTP/1.1\r\n" |
| 9987 | "Host: www.example.org\r\n" |
| 9988 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9989 | }; |
| 9990 | |
| 9991 | MockRead data_reads1[] = { |
| 9992 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9993 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9994 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9995 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9996 | }; |
| 9997 | |
| 9998 | // Resend with authorization from MyRealm's cache. |
| 9999 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10000 | MockWrite( |
| 10001 | "GET /x/1 HTTP/1.1\r\n" |
| 10002 | "Host: www.example.org\r\n" |
| 10003 | "Connection: keep-alive\r\n" |
| 10004 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10005 | }; |
| 10006 | |
| 10007 | // Sever accepts the authorization. |
| 10008 | MockRead data_reads2[] = { |
| 10009 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10010 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10011 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10012 | }; |
| 10013 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10014 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10015 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10016 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10017 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10019 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10020 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10021 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10023 | |
| 10024 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10025 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10027 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10028 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10029 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10031 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10032 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10033 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10035 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10036 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10037 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10038 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10039 | } |
| 10040 | |
| 10041 | // ------------------------------------------------------------------------ |
| 10042 | |
| 10043 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 10044 | // cached identity. Should invalidate and re-prompt. |
| 10045 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10046 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10047 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10048 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10049 | request.traffic_annotation = |
| 10050 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10051 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10052 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10053 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10054 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10055 | MockWrite( |
| 10056 | "GET /p/q/t HTTP/1.1\r\n" |
| 10057 | "Host: www.example.org\r\n" |
| 10058 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10059 | }; |
| 10060 | |
| 10061 | MockRead data_reads1[] = { |
| 10062 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10063 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10064 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10065 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10066 | }; |
| 10067 | |
| 10068 | // Resend with authorization from cache for MyRealm. |
| 10069 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10070 | MockWrite( |
| 10071 | "GET /p/q/t HTTP/1.1\r\n" |
| 10072 | "Host: www.example.org\r\n" |
| 10073 | "Connection: keep-alive\r\n" |
| 10074 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10075 | }; |
| 10076 | |
| 10077 | // Sever rejects the authorization. |
| 10078 | MockRead data_reads2[] = { |
| 10079 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10080 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10081 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10082 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10083 | }; |
| 10084 | |
| 10085 | // At this point we should prompt for new credentials for MyRealm. |
| 10086 | // Restart with username=foo3, password=foo4. |
| 10087 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10088 | MockWrite( |
| 10089 | "GET /p/q/t HTTP/1.1\r\n" |
| 10090 | "Host: www.example.org\r\n" |
| 10091 | "Connection: keep-alive\r\n" |
| 10092 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10093 | }; |
| 10094 | |
| 10095 | // Sever accepts the authorization. |
| 10096 | MockRead data_reads3[] = { |
| 10097 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10098 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10099 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10100 | }; |
| 10101 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10102 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10103 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 10104 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10105 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10106 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10107 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10109 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10110 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10111 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10112 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10113 | |
| 10114 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10115 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10116 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10117 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10118 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10119 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10121 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10122 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10123 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10125 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10126 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10127 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10129 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10131 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 10132 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10134 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10135 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10138 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10139 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10140 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10141 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10142 | } |
| 10143 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10144 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10145 | // Tests that nonce count increments when multiple auth attempts |
| 10146 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10147 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 10148 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 10149 | new HttpAuthHandlerDigest::Factory(); |
| 10150 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 10151 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 10152 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10153 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10155 | |
| 10156 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 10157 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10158 | HttpRequestInfo request; |
| 10159 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10160 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10161 | request.traffic_annotation = |
| 10162 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10165 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10166 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10167 | MockWrite( |
| 10168 | "GET /x/y/z HTTP/1.1\r\n" |
| 10169 | "Host: www.example.org\r\n" |
| 10170 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10171 | }; |
| 10172 | |
| 10173 | MockRead data_reads1[] = { |
| 10174 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10175 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 10176 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10177 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10178 | }; |
| 10179 | |
| 10180 | // Resend with authorization (username=foo, password=bar) |
| 10181 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10182 | MockWrite( |
| 10183 | "GET /x/y/z HTTP/1.1\r\n" |
| 10184 | "Host: www.example.org\r\n" |
| 10185 | "Connection: keep-alive\r\n" |
| 10186 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 10187 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 10188 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 10189 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10190 | }; |
| 10191 | |
| 10192 | // Sever accepts the authorization. |
| 10193 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10194 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10195 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10196 | }; |
| 10197 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10198 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10199 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10200 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10201 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10203 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10204 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10205 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10206 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10207 | |
| 10208 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10209 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10211 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10212 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10213 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10215 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10216 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10217 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10218 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10220 | |
| 10221 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10222 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10224 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10225 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10226 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10227 | } |
| 10228 | |
| 10229 | // ------------------------------------------------------------------------ |
| 10230 | |
| 10231 | // Transaction 2: Request another resource in digestive's protection space. |
| 10232 | // This will preemptively add an Authorization header which should have an |
| 10233 | // "nc" value of 2 (as compared to 1 in the first use. |
| 10234 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10235 | HttpRequestInfo request; |
| 10236 | request.method = "GET"; |
| 10237 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 10238 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10239 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10240 | request.traffic_annotation = |
| 10241 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10243 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10244 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10245 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10246 | MockWrite( |
| 10247 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 10248 | "Host: www.example.org\r\n" |
| 10249 | "Connection: keep-alive\r\n" |
| 10250 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 10251 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 10252 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 10253 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10254 | }; |
| 10255 | |
| 10256 | // Sever accepts the authorization. |
| 10257 | MockRead data_reads1[] = { |
| 10258 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10259 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10260 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10261 | }; |
| 10262 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10263 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10264 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10266 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10267 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10268 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10269 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10270 | |
| 10271 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10272 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10274 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10275 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10276 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10277 | } |
| 10278 | } |
| 10279 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10280 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10281 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10282 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10284 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10285 | |
| 10286 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 10287 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10288 | trans.read_buf_len_ = 15; |
| 10289 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10290 | |
| 10291 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10292 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10293 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 10294 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10295 | response->response_time = base::Time::Now(); |
| 10296 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10297 | |
| 10298 | { // Setup state for response_.vary_data |
| 10299 | HttpRequestInfo request; |
| 10300 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 10301 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 10302 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10303 | request.extra_headers.SetHeader("Foo", "1"); |
| 10304 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10305 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10306 | } |
| 10307 | |
| 10308 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10309 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10310 | |
| 10311 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10312 | EXPECT_FALSE(trans.read_buf_); |
| 10313 | EXPECT_EQ(0, trans.read_buf_len_); |
| 10314 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10315 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10316 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 10317 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 10318 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10319 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10320 | } |
| 10321 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10322 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10323 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10324 | HttpRequestInfo request; |
| 10325 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10326 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10327 | request.traffic_annotation = |
| 10328 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10329 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10330 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10331 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10332 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10333 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10334 | MockWrite( |
| 10335 | "GET / HTTP/1.1\r\n" |
| 10336 | "Host: www.example.org\r\n" |
| 10337 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10338 | }; |
| 10339 | |
| 10340 | MockRead data_reads[] = { |
| 10341 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10342 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10343 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10344 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10345 | }; |
| 10346 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 10347 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10348 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10349 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10350 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10351 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10352 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 10355 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10357 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10359 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10361 | |
| 10362 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10363 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10365 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10367 | |
| 10368 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10371 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10372 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10373 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10374 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10375 | } |
| 10376 | |
| 10377 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 10378 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10379 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10380 | session_deps_.proxy_resolution_service = |
| 10381 | ConfiguredProxyResolutionService::CreateFixed( |
| 10382 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10383 | |
| 10384 | HttpRequestInfo request; |
| 10385 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10386 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10387 | request.traffic_annotation = |
| 10388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10389 | |
| 10390 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10391 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10392 | "Host: www.example.org:443\r\n" |
| 10393 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10394 | }; |
| 10395 | |
| 10396 | MockRead proxy_reads[] = { |
| 10397 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10398 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10399 | }; |
| 10400 | |
| 10401 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10402 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10403 | "Host: www.example.org:443\r\n" |
| 10404 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10405 | MockWrite("GET / HTTP/1.1\r\n" |
| 10406 | "Host: www.example.org\r\n" |
| 10407 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10408 | }; |
| 10409 | |
| 10410 | MockRead data_reads[] = { |
| 10411 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10412 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10413 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10414 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10415 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10416 | }; |
| 10417 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10418 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 10419 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10420 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10421 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10422 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10423 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 10426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10428 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10429 | |
| 10430 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10431 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10432 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10433 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10434 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10438 | |
| 10439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10440 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10442 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10444 | |
| 10445 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10448 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10449 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10450 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10451 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10452 | } |
| 10453 | } |
| 10454 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10455 | |
| 10456 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10457 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10458 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10459 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10460 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10461 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10462 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10463 | |
| 10464 | HttpRequestInfo request; |
| 10465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10466 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10467 | request.traffic_annotation = |
| 10468 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10469 | |
| 10470 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10471 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10472 | "Host: www.example.org:443\r\n" |
| 10473 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10474 | MockWrite("GET / HTTP/1.1\r\n" |
| 10475 | "Host: www.example.org\r\n" |
| 10476 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10477 | }; |
| 10478 | |
| 10479 | MockRead data_reads[] = { |
| 10480 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10481 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10482 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10483 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10484 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10485 | }; |
| 10486 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10487 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10488 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 10489 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10490 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10491 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 10493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10495 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10499 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10500 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10501 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10502 | |
| 10503 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10504 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10505 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10506 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10507 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10508 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10509 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10510 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10511 | EXPECT_EQ(200, response->headers->response_code()); |
| 10512 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10513 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10514 | |
| 10515 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10516 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10517 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10518 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10519 | } |
| 10520 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 10521 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10522 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10523 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10524 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10525 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10526 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10527 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10528 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10529 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 10530 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 10531 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10532 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10533 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10534 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10535 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10536 | request.traffic_annotation = |
| 10537 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10538 | |
| 10539 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10540 | MockWrite(ASYNC, 0, |
| 10541 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10542 | "Host: www.example.org:443\r\n" |
| 10543 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10544 | }; |
| 10545 | |
| 10546 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10547 | // Pause on first read. |
| 10548 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 10549 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 10550 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 10551 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10552 | }; |
| 10553 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10554 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10555 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10556 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10557 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10558 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10560 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10561 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10563 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10564 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10565 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10567 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 10568 | |
| 10569 | // Host resolution takes |kTimeIncrement|. |
| 10570 | FastForwardBy(kTimeIncrement); |
| 10571 | // Resolving the current request with |ResolveNow| will cause the pending |
| 10572 | // request to instantly complete, and the async connect will start as well. |
| 10573 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 10574 | |
| 10575 | // Connecting takes |kTimeIncrement|. |
| 10576 | FastForwardBy(kTimeIncrement); |
| 10577 | data.RunUntilPaused(); |
| 10578 | |
| 10579 | // The server takes |kTimeIncrement| to respond. |
| 10580 | FastForwardBy(kTimeIncrement); |
| 10581 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10582 | |
| 10583 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10584 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10585 | } |
| 10586 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10587 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 10588 | TEST_F(HttpNetworkTransactionTest, |
| 10589 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 10590 | base::HistogramTester histograms; |
| 10591 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10592 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10593 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10594 | RecordingTestNetLog net_log; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10595 | session_deps_.net_log = &net_log; |
| 10596 | |
| 10597 | HttpRequestInfo request; |
| 10598 | request.method = "GET"; |
| 10599 | request.url = GURL("https://www.example.org/"); |
| 10600 | request.traffic_annotation = |
| 10601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10602 | |
| 10603 | MockWrite data_writes[] = { |
| 10604 | MockWrite(ASYNC, 0, |
| 10605 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10606 | "Host: www.example.org:443\r\n" |
| 10607 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10608 | }; |
| 10609 | |
| 10610 | MockRead data_reads[] = { |
| 10611 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 10612 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 10613 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 10614 | }; |
| 10615 | |
| 10616 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 10617 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 10618 | |
| 10619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 10621 | |
| 10622 | TestCompletionCallback callback; |
| 10623 | |
| 10624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10626 | |
| 10627 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10629 | |
| 10630 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10631 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10632 | } |
| 10633 | |
| 10634 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 10635 | // request for main frames. |
| 10636 | TEST_F(HttpNetworkTransactionTest, |
| 10637 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 10638 | base::HistogramTester histograms; |
| 10639 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10640 | ConfiguredProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10641 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10642 | RecordingTestNetLog net_log; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10643 | session_deps_.net_log = &net_log; |
| 10644 | |
| 10645 | HttpRequestInfo request; |
| 10646 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 10647 | request.method = "GET"; |
| 10648 | request.url = GURL("https://www.example.org/"); |
| 10649 | request.traffic_annotation = |
| 10650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10651 | |
| 10652 | MockWrite data_writes[] = { |
| 10653 | MockWrite(ASYNC, 0, |
| 10654 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10655 | "Host: www.example.org:443\r\n" |
| 10656 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10657 | }; |
| 10658 | |
| 10659 | MockRead data_reads[] = { |
| 10660 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 10661 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 10662 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 10663 | }; |
| 10664 | |
| 10665 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 10666 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 10667 | |
| 10668 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10669 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 10670 | |
| 10671 | TestCompletionCallback callback; |
| 10672 | |
| 10673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10675 | |
| 10676 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10678 | |
| 10679 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10680 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10681 | } |
| 10682 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 10683 | // 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] | 10684 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10685 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10686 | base::HistogramTester histograms; |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10687 | session_deps_.proxy_resolution_service = |
| 10688 | ConfiguredProxyResolutionService::CreateFixed( |
| 10689 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10690 | RecordingTestNetLog net_log; |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10691 | session_deps_.net_log = &net_log; |
| 10692 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10693 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 10694 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10695 | |
| 10696 | HttpRequestInfo request; |
| 10697 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10698 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10699 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10700 | request.traffic_annotation = |
| 10701 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10702 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10703 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10704 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10705 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10706 | spdy::SpdySerializedFrame goaway( |
| 10707 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10708 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10709 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10710 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10711 | }; |
| 10712 | |
| 10713 | static const char* const kExtraHeaders[] = { |
| 10714 | "location", |
| 10715 | "http://login.example.com/", |
| 10716 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10717 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10718 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10719 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10720 | // Pause on first read. |
| 10721 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 10722 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10723 | }; |
| 10724 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10725 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10726 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10727 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10728 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10732 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10736 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10737 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10739 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10740 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10741 | // Host resolution takes |kTimeIncrement|. |
| 10742 | FastForwardBy(kTimeIncrement); |
| 10743 | // Resolving the current request with |ResolveNow| will cause the pending |
| 10744 | // request to instantly complete, and the async connect will start as well. |
| 10745 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 10746 | |
| 10747 | // Connecting takes |kTimeIncrement|. |
| 10748 | FastForwardBy(kTimeIncrement); |
| 10749 | data.RunUntilPaused(); |
| 10750 | |
| 10751 | FastForwardBy(kTimeIncrement); |
| 10752 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10753 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10754 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10755 | } |
| 10756 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 10757 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10758 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10759 | session_deps_.proxy_resolution_service = |
| 10760 | ConfiguredProxyResolutionService::CreateFixed( |
| 10761 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10762 | |
| 10763 | HttpRequestInfo request; |
| 10764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10765 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10766 | request.traffic_annotation = |
| 10767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10768 | |
| 10769 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10770 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10771 | "Host: www.example.org:443\r\n" |
| 10772 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10773 | }; |
| 10774 | |
| 10775 | MockRead data_reads[] = { |
| 10776 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 10777 | MockRead("Content-Length: 23\r\n\r\n"), |
| 10778 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10779 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10780 | }; |
| 10781 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10782 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10783 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10784 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10787 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10788 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10789 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10792 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10793 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10795 | |
| 10796 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10797 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10798 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 10799 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10800 | } |
| 10801 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 10802 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10803 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10804 | session_deps_.proxy_resolution_service = |
| 10805 | ConfiguredProxyResolutionService::CreateFixed( |
| 10806 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10807 | |
| 10808 | HttpRequestInfo request; |
| 10809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10810 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10811 | request.traffic_annotation = |
| 10812 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10813 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10814 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10815 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10816 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10817 | spdy::SpdySerializedFrame rst( |
| 10818 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10819 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10820 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10821 | }; |
| 10822 | |
| 10823 | static const char* const kExtraHeaders[] = { |
| 10824 | "location", |
| 10825 | "http://login.example.com/", |
| 10826 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10827 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10828 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10829 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10830 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10831 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10832 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10833 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10834 | }; |
| 10835 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10836 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10837 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10838 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10839 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10840 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10841 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10843 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10847 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10848 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10850 | |
| 10851 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10852 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10853 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 10854 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10855 | } |
| 10856 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10857 | // Test the request-challenge-retry sequence for basic auth, through |
| 10858 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10859 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10860 | HttpRequestInfo request; |
| 10861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10862 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10863 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 10864 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10865 | request.traffic_annotation = |
| 10866 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10867 | |
| 10868 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10869 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10870 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10871 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10872 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10873 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10875 | |
| 10876 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10877 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10878 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10879 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10880 | spdy::SpdySerializedFrame rst( |
| 10881 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10882 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10883 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10884 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10885 | // be issuing -- the final header line contains the credentials. |
| 10886 | const char* const kAuthCredentials[] = { |
| 10887 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 10888 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10889 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10890 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 10891 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10892 | HostPortPair("www.example.org", 443))); |
| 10893 | // fetch https://www.example.org/ via HTTP |
| 10894 | const char get[] = |
| 10895 | "GET / HTTP/1.1\r\n" |
| 10896 | "Host: www.example.org\r\n" |
| 10897 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10898 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10899 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10900 | |
| 10901 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10902 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 10903 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10904 | }; |
| 10905 | |
| 10906 | // The proxy responds to the connect with a 407, using a persistent |
| 10907 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10908 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10909 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10910 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 10911 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10912 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10913 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10914 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10915 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10916 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10917 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 10918 | "Content-Length: 5\r\n\r\n"; |
| 10919 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10920 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10921 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10922 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10923 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10924 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10925 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 10926 | CreateMockRead(conn_resp, 4, ASYNC), |
| 10927 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 10928 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10929 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10930 | }; |
| 10931 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10932 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10933 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10934 | // Negotiate SPDY to the proxy |
| 10935 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10936 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10938 | // Vanilla SSL to the server |
| 10939 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10940 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10941 | |
| 10942 | TestCompletionCallback callback1; |
| 10943 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10944 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10945 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10946 | |
| 10947 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10949 | |
| 10950 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10951 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 10952 | auto entries = log.GetEntries(); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10953 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10954 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10955 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10956 | ExpectLogContainsSomewhere( |
| 10957 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10958 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10959 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10960 | |
| 10961 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10962 | ASSERT_TRUE(response); |
| 10963 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10964 | EXPECT_EQ(407, response->headers->response_code()); |
| 10965 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10966 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 10967 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10968 | |
| 10969 | TestCompletionCallback callback2; |
| 10970 | |
| 10971 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10972 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10974 | |
| 10975 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10977 | |
| 10978 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10979 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10980 | |
| 10981 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10982 | EXPECT_EQ(200, response->headers->response_code()); |
| 10983 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10984 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10985 | |
| 10986 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10987 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10988 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10989 | LoadTimingInfo load_timing_info; |
| 10990 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10991 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10992 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10993 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10994 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 10995 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10996 | } |
| 10997 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10998 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10999 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11000 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11001 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11002 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11003 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 11004 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11005 | HttpRequestInfo request; |
| 11006 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11007 | request.traffic_annotation = |
| 11008 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11009 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11010 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11011 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11012 | push_request.method = "GET"; |
| 11013 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11014 | push_request.traffic_annotation = |
| 11015 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11016 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11017 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11018 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11019 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11020 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11021 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11022 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11023 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 11024 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 11025 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11028 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11029 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11030 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11031 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11032 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11033 | |
| 11034 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11035 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11036 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11037 | }; |
| 11038 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11039 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11040 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 11041 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11042 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11043 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11044 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11045 | spdy::SpdySerializedFrame stream1_body( |
| 11046 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11047 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11048 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 11049 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11050 | |
| 11051 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 11052 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 11053 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11054 | CreateMockRead(stream1_body, 4, ASYNC), |
| 11055 | CreateMockRead(stream2_body, 5, ASYNC), |
| 11056 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11057 | }; |
| 11058 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11059 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11060 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11061 | // Negotiate SPDY to the proxy |
| 11062 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11063 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11065 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11066 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11067 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11068 | TestCompletionCallback callback; |
| 11069 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11071 | |
| 11072 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11073 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11075 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11076 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11077 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11078 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11080 | |
| 11081 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11083 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 11084 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11085 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11086 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11087 | |
| 11088 | EXPECT_EQ(200, response->headers->response_code()); |
| 11089 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11090 | |
| 11091 | std::string response_data; |
| 11092 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11094 | EXPECT_EQ("hello!", response_data); |
| 11095 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11096 | LoadTimingInfo load_timing_info; |
| 11097 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11098 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11099 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11100 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11101 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11102 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11103 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 11104 | |
| 11105 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11106 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11107 | EXPECT_EQ("pushed", response_data); |
| 11108 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11109 | LoadTimingInfo push_load_timing_info; |
| 11110 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 11111 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 11112 | // The transactions should share a socket ID, despite being for different |
| 11113 | // origins. |
| 11114 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 11115 | push_load_timing_info.socket_log_id); |
| 11116 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11117 | trans.reset(); |
| 11118 | push_trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11119 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11120 | } |
| 11121 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11122 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11123 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11124 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11125 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11126 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 11127 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11128 | HttpRequestInfo request; |
| 11129 | |
| 11130 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11131 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11132 | request.traffic_annotation = |
| 11133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11134 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11135 | session_deps_.proxy_resolution_service = |
| 11136 | ConfiguredProxyResolutionService::CreateFixed( |
| 11137 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11138 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11139 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11140 | |
| 11141 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 11142 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 11143 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11144 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11146 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11147 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11148 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11149 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11150 | spdy::SpdySerializedFrame push_rst( |
| 11151 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11152 | |
| 11153 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11154 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11155 | }; |
| 11156 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11157 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11158 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11159 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11160 | spdy::SpdySerializedFrame stream1_body( |
| 11161 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11162 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11163 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11164 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11165 | |
| 11166 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11167 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 11168 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 11169 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 11170 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11171 | }; |
| 11172 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11173 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11174 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11175 | // Negotiate SPDY to the proxy |
| 11176 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11177 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11179 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11180 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11181 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11182 | TestCompletionCallback callback; |
| 11183 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11185 | |
| 11186 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11187 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11188 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11189 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11190 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11191 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11192 | |
| 11193 | EXPECT_EQ(200, response->headers->response_code()); |
| 11194 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11195 | |
| 11196 | std::string response_data; |
| 11197 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11198 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11199 | EXPECT_EQ("hello!", response_data); |
| 11200 | |
| 11201 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11202 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11203 | } |
| 11204 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11205 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 11206 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11207 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11208 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11209 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11210 | proxy_delegate->set_trusted_spdy_proxy( |
| 11211 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 11212 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11213 | HttpRequestInfo request; |
| 11214 | |
| 11215 | request.method = "GET"; |
| 11216 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11217 | request.traffic_annotation = |
| 11218 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11219 | |
| 11220 | // Configure against https proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11221 | session_deps_.proxy_resolution_service = |
| 11222 | ConfiguredProxyResolutionService::CreateFixed( |
| 11223 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11224 | RecordingBoundTestNetLog log; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11225 | session_deps_.net_log = log.bound().net_log(); |
| 11226 | |
| 11227 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 11228 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 11229 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11230 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11232 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11233 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11234 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11235 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11236 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11237 | |
| 11238 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11239 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11240 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11241 | }; |
| 11242 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11243 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11244 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11245 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11246 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 11247 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11248 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11249 | spdy::SpdySerializedFrame stream1_body( |
| 11250 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11251 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11252 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11253 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11254 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11255 | spdy::SpdySerializedFrame stream2_body( |
| 11256 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11257 | |
| 11258 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11259 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 11260 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11261 | CreateMockRead(stream1_body, 4, ASYNC), |
| 11262 | CreateMockRead(stream2_body, 5, ASYNC), |
| 11263 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11264 | }; |
| 11265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11266 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11267 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11268 | // Negotiate SPDY to the proxy |
| 11269 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11270 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 11272 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11273 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11274 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11275 | TestCompletionCallback callback; |
| 11276 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11278 | |
| 11279 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11280 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11281 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11282 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11283 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11284 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11285 | |
| 11286 | EXPECT_EQ(200, response->headers->response_code()); |
| 11287 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11288 | |
| 11289 | std::string response_data; |
| 11290 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11291 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11292 | EXPECT_EQ("hello!", response_data); |
| 11293 | |
| 11294 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11295 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11296 | } |
| 11297 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11298 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 11299 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11300 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11301 | session_deps_.proxy_resolution_service = |
| 11302 | ConfiguredProxyResolutionService::CreateFixed( |
| 11303 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11304 | |
| 11305 | HttpRequestInfo request; |
| 11306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11307 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11308 | request.traffic_annotation = |
| 11309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11310 | |
| 11311 | // Attempt to fetch the URL from a server with a bad cert |
| 11312 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11313 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11314 | "Host: www.example.org:443\r\n" |
| 11315 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11316 | }; |
| 11317 | |
| 11318 | MockRead bad_cert_reads[] = { |
| 11319 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11320 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11321 | }; |
| 11322 | |
| 11323 | // Attempt to fetch the URL with a good cert |
| 11324 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11325 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11326 | "Host: www.example.org:443\r\n" |
| 11327 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11328 | MockWrite("GET / HTTP/1.1\r\n" |
| 11329 | "Host: www.example.org\r\n" |
| 11330 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11331 | }; |
| 11332 | |
| 11333 | MockRead good_cert_reads[] = { |
| 11334 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 11335 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11336 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11337 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11338 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11339 | }; |
| 11340 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11341 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 11342 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11343 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 11344 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11345 | |
| 11346 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11347 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11348 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 11349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11350 | |
| 11351 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11356 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11358 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11359 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11361 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11363 | |
| 11364 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11365 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11367 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11369 | |
| 11370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11371 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11374 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11375 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11376 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11377 | } |
| 11378 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11379 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11380 | HttpRequestInfo request; |
| 11381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11382 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11383 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 11384 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11385 | request.traffic_annotation = |
| 11386 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11390 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11391 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11392 | MockWrite( |
| 11393 | "GET / HTTP/1.1\r\n" |
| 11394 | "Host: www.example.org\r\n" |
| 11395 | "Connection: keep-alive\r\n" |
| 11396 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11397 | }; |
| 11398 | |
| 11399 | // Lastly, the server responds with the actual content. |
| 11400 | MockRead data_reads[] = { |
| 11401 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11402 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11403 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11404 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11405 | }; |
| 11406 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11407 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11408 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11410 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11412 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11414 | |
| 11415 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11417 | } |
| 11418 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11419 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11420 | // Test user agent values, used both for the request header of the original |
| 11421 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 11422 | // no request header / no HttpUserAgentSettings object. |
| 11423 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11424 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11425 | for (const char* setting_user_agent : kTestUserAgents) { |
| 11426 | if (!setting_user_agent) { |
| 11427 | session_deps_.http_user_agent_settings.reset(); |
| 11428 | } else { |
| 11429 | session_deps_.http_user_agent_settings = |
| 11430 | std::make_unique<StaticHttpUserAgentSettings>( |
| 11431 | std::string() /* accept-language */, setting_user_agent); |
| 11432 | } |
| 11433 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11434 | ConfiguredProxyResolutionService::CreateFixed( |
| 11435 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11437 | for (const char* request_user_agent : kTestUserAgents) { |
| 11438 | HttpRequestInfo request; |
| 11439 | request.method = "GET"; |
| 11440 | request.url = GURL("https://www.example.org/"); |
| 11441 | if (request_user_agent) { |
| 11442 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 11443 | request_user_agent); |
| 11444 | } |
| 11445 | request.traffic_annotation = |
| 11446 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11447 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11448 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11449 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11450 | std::string expected_request; |
| 11451 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 11452 | expected_request = |
| 11453 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11454 | "Host: www.example.org:443\r\n" |
| 11455 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 11456 | } else { |
| 11457 | expected_request = base::StringPrintf( |
| 11458 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11459 | "Host: www.example.org:443\r\n" |
| 11460 | "Proxy-Connection: keep-alive\r\n" |
| 11461 | "User-Agent: %s\r\n\r\n", |
| 11462 | setting_user_agent); |
| 11463 | } |
| 11464 | MockWrite data_writes[] = { |
| 11465 | MockWrite(expected_request.c_str()), |
| 11466 | }; |
| 11467 | MockRead data_reads[] = { |
| 11468 | // Return an error, so the transaction stops here (this test isn't |
| 11469 | // interested in the rest). |
| 11470 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 11471 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11472 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 11473 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11474 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11475 | StaticSocketDataProvider data(data_reads, data_writes); |
| 11476 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11477 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11478 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11479 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11480 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11482 | |
| 11483 | rv = callback.WaitForResult(); |
| 11484 | EXPECT_THAT(rv, IsOk()); |
| 11485 | } |
| 11486 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11487 | } |
| 11488 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11489 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11490 | HttpRequestInfo request; |
| 11491 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11492 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 11493 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 11494 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11495 | request.traffic_annotation = |
| 11496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11500 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11501 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11502 | MockWrite( |
| 11503 | "GET / HTTP/1.1\r\n" |
| 11504 | "Host: www.example.org\r\n" |
| 11505 | "Connection: keep-alive\r\n" |
| 11506 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11507 | }; |
| 11508 | |
| 11509 | // Lastly, the server responds with the actual content. |
| 11510 | MockRead data_reads[] = { |
| 11511 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11512 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11513 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11514 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11515 | }; |
| 11516 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11517 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11518 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11520 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11521 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11522 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11524 | |
| 11525 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11526 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11527 | } |
| 11528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11529 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11530 | HttpRequestInfo request; |
| 11531 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11532 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11533 | request.traffic_annotation = |
| 11534 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11535 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11537 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11538 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11539 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11540 | MockWrite( |
| 11541 | "POST / HTTP/1.1\r\n" |
| 11542 | "Host: www.example.org\r\n" |
| 11543 | "Connection: keep-alive\r\n" |
| 11544 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11545 | }; |
| 11546 | |
| 11547 | // Lastly, the server responds with the actual content. |
| 11548 | MockRead data_reads[] = { |
| 11549 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11550 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11551 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11552 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11553 | }; |
| 11554 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11555 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11558 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11559 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11562 | |
| 11563 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11564 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11565 | } |
| 11566 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11567 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11568 | HttpRequestInfo request; |
| 11569 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11570 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11571 | request.traffic_annotation = |
| 11572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11576 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11577 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11578 | MockWrite( |
| 11579 | "PUT / HTTP/1.1\r\n" |
| 11580 | "Host: www.example.org\r\n" |
| 11581 | "Connection: keep-alive\r\n" |
| 11582 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11583 | }; |
| 11584 | |
| 11585 | // Lastly, the server responds with the actual content. |
| 11586 | MockRead data_reads[] = { |
| 11587 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11588 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11589 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11590 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11591 | }; |
| 11592 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11593 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11596 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11600 | |
| 11601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11602 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11603 | } |
| 11604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11605 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11606 | HttpRequestInfo request; |
| 11607 | request.method = "HEAD"; |
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] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11615 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 11616 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 11617 | "Host: www.example.org\r\n" |
| 11618 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11619 | }; |
| 11620 | |
| 11621 | // Lastly, the server responds with the actual content. |
| 11622 | MockRead data_reads[] = { |
| 11623 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11624 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11625 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11626 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11627 | }; |
| 11628 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11629 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11630 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11631 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11632 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11633 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11636 | |
| 11637 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11638 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11639 | } |
| 11640 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11641 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11642 | HttpRequestInfo request; |
| 11643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11644 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11645 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11646 | request.traffic_annotation = |
| 11647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11648 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11649 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11650 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11651 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11652 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11653 | MockWrite( |
| 11654 | "GET / HTTP/1.1\r\n" |
| 11655 | "Host: www.example.org\r\n" |
| 11656 | "Connection: keep-alive\r\n" |
| 11657 | "Pragma: no-cache\r\n" |
| 11658 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11659 | }; |
| 11660 | |
| 11661 | // Lastly, the server responds with the actual content. |
| 11662 | MockRead data_reads[] = { |
| 11663 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11665 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11667 | }; |
| 11668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11669 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11672 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11676 | |
| 11677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11678 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11679 | } |
| 11680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11681 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11682 | HttpRequestInfo request; |
| 11683 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11684 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11685 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11686 | request.traffic_annotation = |
| 11687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11691 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11692 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11693 | MockWrite( |
| 11694 | "GET / HTTP/1.1\r\n" |
| 11695 | "Host: www.example.org\r\n" |
| 11696 | "Connection: keep-alive\r\n" |
| 11697 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11698 | }; |
| 11699 | |
| 11700 | // Lastly, the server responds with the actual content. |
| 11701 | MockRead data_reads[] = { |
| 11702 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11703 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11704 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11705 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11706 | }; |
| 11707 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11708 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11711 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11712 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11713 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11715 | |
| 11716 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11717 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11718 | } |
| 11719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11720 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11721 | HttpRequestInfo request; |
| 11722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11723 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11724 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11725 | request.traffic_annotation = |
| 11726 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11730 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11731 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11732 | MockWrite( |
| 11733 | "GET / HTTP/1.1\r\n" |
| 11734 | "Host: www.example.org\r\n" |
| 11735 | "Connection: keep-alive\r\n" |
| 11736 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11737 | }; |
| 11738 | |
| 11739 | // Lastly, the server responds with the actual content. |
| 11740 | MockRead data_reads[] = { |
| 11741 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11742 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11743 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11744 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11745 | }; |
| 11746 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11747 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11750 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11752 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11754 | |
| 11755 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11756 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11757 | } |
| 11758 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11759 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11760 | HttpRequestInfo request; |
| 11761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11762 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11763 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 11764 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 11765 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11766 | request.traffic_annotation = |
| 11767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11768 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11771 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11772 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11773 | MockWrite( |
| 11774 | "GET / HTTP/1.1\r\n" |
| 11775 | "Host: www.example.org\r\n" |
| 11776 | "Connection: keep-alive\r\n" |
| 11777 | "referer: www.foo.com\r\n" |
| 11778 | "hEllo: Kitty\r\n" |
| 11779 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11780 | }; |
| 11781 | |
| 11782 | // Lastly, the server responds with the actual content. |
| 11783 | MockRead data_reads[] = { |
| 11784 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11785 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11786 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11788 | }; |
| 11789 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11790 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11793 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11795 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11797 | |
| 11798 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11799 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11800 | } |
| 11801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11802 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11803 | HttpRequestInfo request; |
| 11804 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11805 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11806 | request.traffic_annotation = |
| 11807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11808 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11809 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11810 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11811 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11812 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11813 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11816 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11817 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11818 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11819 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11820 | |
| 11821 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11822 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11823 | MockWrite("GET / HTTP/1.1\r\n" |
| 11824 | "Host: www.example.org\r\n" |
| 11825 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11826 | |
| 11827 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11828 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11829 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11830 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11831 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11833 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11836 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11838 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11840 | |
| 11841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11842 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11844 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11845 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11846 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11847 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11848 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11849 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11850 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11851 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11852 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11853 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11854 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11855 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11856 | EXPECT_EQ("Payload", response_text); |
| 11857 | } |
| 11858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11859 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11860 | HttpRequestInfo request; |
| 11861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11862 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11863 | request.traffic_annotation = |
| 11864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11865 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11866 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11867 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11868 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11869 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11870 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11871 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11873 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11874 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11875 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 11876 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11877 | |
| 11878 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11879 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11880 | base::size(write_buffer)), |
| 11881 | MockWrite("GET / HTTP/1.1\r\n" |
| 11882 | "Host: www.example.org\r\n" |
| 11883 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11884 | |
| 11885 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11886 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 11887 | base::size(read_buffer)), |
| 11888 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11889 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11890 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11891 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11892 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11893 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11894 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11895 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11898 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11899 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11900 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11902 | |
| 11903 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11904 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11905 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11906 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11907 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11908 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11909 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11912 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11913 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11914 | |
| 11915 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11916 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11917 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11918 | EXPECT_EQ("Payload", response_text); |
| 11919 | } |
| 11920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11921 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11922 | HttpRequestInfo request; |
| 11923 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11924 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11925 | request.traffic_annotation = |
| 11926 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11927 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11928 | session_deps_.proxy_resolution_service = |
| 11929 | ConfiguredProxyResolutionService::CreateFixed( |
| 11930 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11931 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11932 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11933 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11936 | |
| 11937 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11938 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11939 | |
| 11940 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11941 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11942 | MockWrite("GET / HTTP/1.1\r\n" |
| 11943 | "Host: www.example.org\r\n" |
| 11944 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11945 | |
| 11946 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11947 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11948 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11949 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11950 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11951 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11952 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11953 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11954 | |
| 11955 | TestCompletionCallback callback; |
| 11956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11957 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11959 | |
| 11960 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11961 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11963 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11964 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11965 | |
| 11966 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11967 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11968 | TestLoadTimingNotReused(load_timing_info, |
| 11969 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11970 | |
| 11971 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11972 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11974 | EXPECT_EQ("Payload", response_text); |
| 11975 | } |
| 11976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11977 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11978 | HttpRequestInfo request; |
| 11979 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11980 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11981 | request.traffic_annotation = |
| 11982 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11983 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11984 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11985 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11986 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11987 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11988 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11992 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11993 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11994 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11995 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11996 | 0x05, // Version |
| 11997 | 0x01, // Command (CONNECT) |
| 11998 | 0x00, // Reserved. |
| 11999 | 0x03, // Address type (DOMAINNAME). |
| 12000 | 0x0F, // Length of domain (15) |
| 12001 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 12002 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12003 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12004 | const char kSOCKS5OkResponse[] = |
| 12005 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 12006 | |
| 12007 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12008 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 12009 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 12010 | MockWrite("GET / HTTP/1.1\r\n" |
| 12011 | "Host: www.example.org\r\n" |
| 12012 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12013 | |
| 12014 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12015 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 12016 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 12017 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12019 | MockRead("Payload"), |
| 12020 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12022 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12025 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12026 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12027 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12029 | |
| 12030 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12031 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12033 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12034 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12035 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12036 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12037 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12038 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12039 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12040 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 12041 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12042 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12043 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12044 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12045 | EXPECT_EQ("Payload", response_text); |
| 12046 | } |
| 12047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12048 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12049 | HttpRequestInfo request; |
| 12050 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12051 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12052 | request.traffic_annotation = |
| 12053 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12054 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12055 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12056 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12057 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 12058 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12059 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12062 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12063 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12064 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 12065 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12066 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12067 | 0x05, // Version |
| 12068 | 0x01, // Command (CONNECT) |
| 12069 | 0x00, // Reserved. |
| 12070 | 0x03, // Address type (DOMAINNAME). |
| 12071 | 0x0F, // Length of domain (15) |
| 12072 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 12073 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12074 | }; |
| 12075 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12076 | const char kSOCKS5OkResponse[] = |
| 12077 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 12078 | |
| 12079 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12080 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12081 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12082 | base::size(kSOCKS5OkRequest)), |
| 12083 | MockWrite("GET / HTTP/1.1\r\n" |
| 12084 | "Host: www.example.org\r\n" |
| 12085 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12086 | |
| 12087 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12088 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 12089 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 12090 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12091 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12092 | MockRead("Payload"), |
| 12093 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12094 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12095 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12097 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12098 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12101 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12102 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12103 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12105 | |
| 12106 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12107 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12108 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12109 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12110 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12111 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12112 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12113 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12114 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12115 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12116 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12117 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12118 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12119 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12121 | EXPECT_EQ("Payload", response_text); |
| 12122 | } |
| 12123 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12124 | namespace { |
| 12125 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12126 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12127 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12128 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12129 | std::string proxy_server; |
| 12130 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12131 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 12132 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12133 | }; |
| 12134 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12135 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12136 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12138 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12139 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12140 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12141 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12142 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12143 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 12144 | url::SchemeHostPort("https", "host.with.alternate", 443), |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12145 | NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12146 | |
| 12147 | return session; |
| 12148 | } |
| 12149 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12150 | int GroupIdTransactionHelper(const std::string& url, |
| 12151 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12152 | HttpRequestInfo request; |
| 12153 | request.method = "GET"; |
| 12154 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12155 | request.traffic_annotation = |
| 12156 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12160 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12161 | |
| 12162 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12163 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12164 | } |
| 12165 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12166 | } // namespace |
| 12167 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12168 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 12169 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12170 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12171 | "", // unused |
| 12172 | "http://www.example.org/direct", |
| 12173 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12174 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12175 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12176 | NetworkIsolationKey(), |
| 12177 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12178 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12179 | }, |
| 12180 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12181 | "", // unused |
| 12182 | "http://[2001:1418:13:1::25]/direct", |
| 12183 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 12184 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12185 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12186 | NetworkIsolationKey(), |
| 12187 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12188 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12189 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12190 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12191 | // SSL Tests |
| 12192 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12193 | "", // unused |
| 12194 | "https://www.example.org/direct_ssl", |
| 12195 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12196 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12197 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12198 | NetworkIsolationKey(), |
| 12199 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12200 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12201 | }, |
| 12202 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12203 | "", // unused |
| 12204 | "https://[2001:1418:13:1::25]/direct", |
| 12205 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 12206 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12207 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12208 | NetworkIsolationKey(), |
| 12209 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12210 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12211 | }, |
| 12212 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12213 | "", // unused |
| 12214 | "https://host.with.alternate/direct", |
| 12215 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 12216 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12217 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12218 | NetworkIsolationKey(), |
| 12219 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12220 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12221 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12222 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12223 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12224 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12225 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12226 | ConfiguredProxyResolutionService::CreateFixed( |
| 12227 | tests[i].proxy_server, TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12228 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12229 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12230 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12231 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12232 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 12233 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12234 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 12235 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 12236 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12237 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12238 | |
| 12239 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12240 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 12241 | EXPECT_EQ(tests[i].expected_group_id, |
| 12242 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 12243 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12244 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12245 | } |
| 12246 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12247 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 12248 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12249 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12250 | "http_proxy", |
| 12251 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12252 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12253 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12254 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12255 | NetworkIsolationKey(), |
| 12256 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12257 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12258 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12259 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12260 | // SSL Tests |
| 12261 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12262 | "http_proxy", |
| 12263 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12264 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12265 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12266 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12267 | NetworkIsolationKey(), |
| 12268 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12269 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12270 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 12271 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12272 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12273 | "http_proxy", |
| 12274 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12275 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 12276 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12277 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12278 | NetworkIsolationKey(), |
| 12279 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12280 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12281 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12282 | }; |
| 12283 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12284 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12285 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12286 | ConfiguredProxyResolutionService::CreateFixed( |
| 12287 | tests[i].proxy_server, TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12288 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12289 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12290 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12291 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12292 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 12293 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12294 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12295 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 12296 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12297 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 12298 | mock_pool_manager->SetSocketPool(proxy_server, |
| 12299 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12300 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12301 | |
| 12302 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12303 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 12304 | EXPECT_EQ(tests[i].expected_group_id, |
| 12305 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12306 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12307 | } |
| 12308 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12309 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 12310 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12311 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12312 | "socks4://socks_proxy:1080", |
| 12313 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12314 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12315 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12316 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12317 | NetworkIsolationKey(), |
| 12318 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12319 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12320 | }, |
| 12321 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12322 | "socks5://socks_proxy:1080", |
| 12323 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12324 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12325 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12326 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12327 | NetworkIsolationKey(), |
| 12328 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12329 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12330 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12332 | // SSL Tests |
| 12333 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12334 | "socks4://socks_proxy:1080", |
| 12335 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12336 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12337 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12338 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12339 | NetworkIsolationKey(), |
| 12340 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12341 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12342 | }, |
| 12343 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12344 | "socks5://socks_proxy:1080", |
| 12345 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12346 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12347 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12348 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12349 | NetworkIsolationKey(), |
| 12350 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12351 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12352 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 12353 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12354 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12355 | "socks4://socks_proxy:1080", |
| 12356 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12357 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 12358 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12359 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12360 | NetworkIsolationKey(), |
| 12361 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12362 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12363 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12364 | }; |
| 12365 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12366 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12367 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12368 | ConfiguredProxyResolutionService::CreateFixed( |
| 12369 | tests[i].proxy_server, TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12370 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12371 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 12372 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12373 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12374 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 12375 | ProxyServer proxy_server( |
| 12376 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 12377 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12378 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 12379 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12380 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 12381 | mock_pool_manager->SetSocketPool(proxy_server, |
| 12382 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12383 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12385 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12386 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12387 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12388 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 12389 | EXPECT_EQ(tests[i].expected_group_id, |
| 12390 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12391 | } |
| 12392 | } |
| 12393 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12394 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12395 | HttpRequestInfo request; |
| 12396 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12397 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12398 | request.traffic_annotation = |
| 12399 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12400 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12401 | session_deps_.proxy_resolution_service = |
| 12402 | ConfiguredProxyResolutionService::CreateFixed( |
| 12403 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 12404 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 12405 | // This simulates failure resolving all hostnames; that means we will fail |
| 12406 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12407 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 12408 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12409 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12411 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12412 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12413 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12414 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12416 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12417 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12418 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12419 | } |
| 12420 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12421 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12422 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12423 | HttpRequestInfo request; |
| 12424 | request.method = "GET"; |
| 12425 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12426 | request.traffic_annotation = |
| 12427 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12428 | |
| 12429 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12430 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12431 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12432 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12434 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12436 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12438 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12439 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12440 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12441 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12442 | |
| 12443 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12444 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12445 | |
| 12446 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12447 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12448 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12449 | } |
| 12450 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12451 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12452 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12453 | HttpRequestInfo request; |
| 12454 | request.method = "GET"; |
| 12455 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12456 | request.traffic_annotation = |
| 12457 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12458 | |
| 12459 | MockRead data_reads[] = { |
| 12460 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12462 | }; |
| 12463 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12464 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12468 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12469 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12472 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12474 | |
| 12475 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12476 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12479 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12480 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12481 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12482 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 12483 | |
| 12484 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12485 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12486 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12487 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12488 | |
| 12489 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12490 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12491 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12492 | } |
| 12493 | |
| 12494 | // Make sure that a dropped connection while draining the body for auth |
| 12495 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12496 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12497 | HttpRequestInfo request; |
| 12498 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12499 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12500 | request.traffic_annotation = |
| 12501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12502 | |
| 12503 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12504 | MockWrite( |
| 12505 | "GET / HTTP/1.1\r\n" |
| 12506 | "Host: www.example.org\r\n" |
| 12507 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12508 | }; |
| 12509 | |
| 12510 | MockRead data_reads1[] = { |
| 12511 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 12512 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 12513 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12514 | MockRead("Content-Length: 14\r\n\r\n"), |
| 12515 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12516 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12517 | }; |
| 12518 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12519 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12520 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12522 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12523 | // be issuing -- the final header line contains the credentials. |
| 12524 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12525 | MockWrite( |
| 12526 | "GET / HTTP/1.1\r\n" |
| 12527 | "Host: www.example.org\r\n" |
| 12528 | "Connection: keep-alive\r\n" |
| 12529 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12530 | }; |
| 12531 | |
| 12532 | // Lastly, the server responds with the actual content. |
| 12533 | MockRead data_reads2[] = { |
| 12534 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12535 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12536 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12537 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12538 | }; |
| 12539 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12540 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12541 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12542 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12544 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12547 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12548 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12549 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12550 | |
| 12551 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12552 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12554 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12555 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12556 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12558 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12560 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12562 | |
| 12563 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12564 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12566 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12567 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12568 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12569 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12570 | } |
| 12571 | |
| 12572 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12573 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12574 | session_deps_.proxy_resolution_service = |
| 12575 | ConfiguredProxyResolutionService::CreateFixed( |
| 12576 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12577 | |
| 12578 | HttpRequestInfo request; |
| 12579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12580 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12581 | request.traffic_annotation = |
| 12582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12583 | |
| 12584 | MockRead proxy_reads[] = { |
| 12585 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12586 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12587 | }; |
| 12588 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12589 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12590 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12591 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12592 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12593 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12595 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12596 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12597 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12598 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12601 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12604 | |
| 12605 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12606 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12607 | } |
| 12608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12609 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12610 | HttpRequestInfo request; |
| 12611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12612 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12613 | request.traffic_annotation = |
| 12614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12615 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12618 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 12619 | MockRead data_reads[] = { |
| 12620 | 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] | 12621 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 12622 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12623 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12624 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12625 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12626 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12627 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12631 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12632 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12635 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12636 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12637 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12638 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 12639 | |
| 12640 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12641 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12642 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 12643 | } |
| 12644 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12645 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 12646 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 12647 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12648 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 12649 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 12650 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12651 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12652 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12653 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12654 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 12655 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12656 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12657 | |
| 12658 | HttpRequestInfo request; |
| 12659 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12660 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12661 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12662 | request.traffic_annotation = |
| 12663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12664 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12667 | |
| 12668 | MockRead data_reads[] = { |
| 12669 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 12670 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12671 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12672 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12673 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12674 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12675 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12676 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12677 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12678 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12680 | |
| 12681 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12682 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12684 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12685 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12686 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 12687 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12688 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 12689 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12690 | } |
| 12691 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12692 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 12693 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 12694 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12695 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 12696 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 12697 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 12698 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 12699 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12701 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12702 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12703 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 12704 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12705 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12706 | |
| 12707 | HttpRequestInfo request; |
| 12708 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12709 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12710 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12711 | request.traffic_annotation = |
| 12712 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12713 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 12714 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12715 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12717 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12718 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12721 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12723 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12725 | |
| 12726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12727 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12728 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 12729 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12730 | } |
| 12731 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12732 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12733 | class FakeUploadElementReader : public UploadElementReader { |
| 12734 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12735 | FakeUploadElementReader() = default; |
| 12736 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12737 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12738 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12739 | |
| 12740 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12741 | int Init(CompletionOnceCallback callback) override { |
| 12742 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12743 | return ERR_IO_PENDING; |
| 12744 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12745 | uint64_t GetContentLength() const override { return 0; } |
| 12746 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12747 | int Read(IOBuffer* buf, |
| 12748 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12749 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12750 | return ERR_FAILED; |
| 12751 | } |
| 12752 | |
| 12753 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12754 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12755 | }; |
| 12756 | |
| 12757 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12758 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 12759 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12760 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12761 | |
| 12762 | HttpRequestInfo request; |
| 12763 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12764 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12765 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12766 | request.traffic_annotation = |
| 12767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12768 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12770 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12771 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12772 | |
| 12773 | StaticSocketDataProvider data; |
| 12774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12775 | |
| 12776 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12777 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12779 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12780 | |
| 12781 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12782 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 12783 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12784 | |
| 12785 | // Return Init()'s result after the transaction gets destroyed. |
| 12786 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12787 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12788 | } |
| 12789 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12790 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12791 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12792 | HttpRequestInfo request; |
| 12793 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12794 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12795 | request.traffic_annotation = |
| 12796 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12797 | |
| 12798 | // First transaction will request a resource and receive a Basic challenge |
| 12799 | // with realm="first_realm". |
| 12800 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12801 | MockWrite( |
| 12802 | "GET / HTTP/1.1\r\n" |
| 12803 | "Host: www.example.org\r\n" |
| 12804 | "Connection: keep-alive\r\n" |
| 12805 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12806 | }; |
| 12807 | MockRead data_reads1[] = { |
| 12808 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12809 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 12810 | "\r\n"), |
| 12811 | }; |
| 12812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12813 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12814 | // for first_realm. The server will reject and provide a challenge with |
| 12815 | // second_realm. |
| 12816 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12817 | MockWrite( |
| 12818 | "GET / HTTP/1.1\r\n" |
| 12819 | "Host: www.example.org\r\n" |
| 12820 | "Connection: keep-alive\r\n" |
| 12821 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 12822 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12823 | }; |
| 12824 | MockRead data_reads2[] = { |
| 12825 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12826 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 12827 | "\r\n"), |
| 12828 | }; |
| 12829 | |
| 12830 | // This again fails, and goes back to first_realm. Make sure that the |
| 12831 | // entry is removed from cache. |
| 12832 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12833 | MockWrite( |
| 12834 | "GET / HTTP/1.1\r\n" |
| 12835 | "Host: www.example.org\r\n" |
| 12836 | "Connection: keep-alive\r\n" |
| 12837 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 12838 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12839 | }; |
| 12840 | MockRead data_reads3[] = { |
| 12841 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12842 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 12843 | "\r\n"), |
| 12844 | }; |
| 12845 | |
| 12846 | // Try one last time (with the correct password) and get the resource. |
| 12847 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12848 | MockWrite( |
| 12849 | "GET / HTTP/1.1\r\n" |
| 12850 | "Host: www.example.org\r\n" |
| 12851 | "Connection: keep-alive\r\n" |
| 12852 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 12853 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12854 | }; |
| 12855 | MockRead data_reads4[] = { |
| 12856 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12857 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12858 | "Content-Length: 5\r\n" |
| 12859 | "\r\n" |
| 12860 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12861 | }; |
| 12862 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12863 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 12864 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 12865 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 12866 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12867 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12868 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 12869 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 12870 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12872 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12873 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12875 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12876 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12877 | // Issue the first request with Authorize headers. There should be a |
| 12878 | // password prompt for first_realm waiting to be filled in after the |
| 12879 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12880 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12882 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12883 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12884 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12885 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12886 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12887 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12888 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12889 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12890 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12891 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12892 | |
| 12893 | // Issue the second request with an incorrect password. There should be a |
| 12894 | // password prompt for second_realm waiting to be filled in after the |
| 12895 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12896 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12897 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 12898 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12900 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12901 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12902 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12903 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12904 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12905 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12906 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12907 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12908 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12909 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12910 | |
| 12911 | // Issue the third request with another incorrect password. There should be |
| 12912 | // a password prompt for first_realm waiting to be filled in. If the password |
| 12913 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 12914 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12915 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12916 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 12917 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12919 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12920 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12921 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12922 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12923 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12924 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12925 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12926 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12927 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12928 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12929 | |
| 12930 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12931 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12932 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 12933 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12935 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12936 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12937 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12938 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12939 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12940 | } |
| 12941 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12942 | // Regression test for https://crbug.com/754395. |
| 12943 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12944 | MockRead data_reads[] = { |
| 12945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12946 | MockRead(kAlternativeServiceHttpHeader), |
| 12947 | MockRead("\r\n"), |
| 12948 | MockRead("hello world"), |
| 12949 | MockRead(SYNCHRONOUS, OK), |
| 12950 | }; |
| 12951 | |
| 12952 | HttpRequestInfo request; |
| 12953 | request.method = "GET"; |
| 12954 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12955 | request.traffic_annotation = |
| 12956 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12957 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12958 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12960 | |
| 12961 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12962 | ssl.ssl_info.cert = |
| 12963 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12964 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12965 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12966 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12967 | |
| 12968 | TestCompletionCallback callback; |
| 12969 | |
| 12970 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12971 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12972 | |
| 12973 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12975 | |
| 12976 | url::SchemeHostPort test_server(request.url); |
| 12977 | HttpServerProperties* http_server_properties = |
| 12978 | session->http_server_properties(); |
| 12979 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12980 | http_server_properties |
| 12981 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12982 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12983 | |
| 12984 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12985 | |
| 12986 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12987 | ASSERT_TRUE(response); |
| 12988 | ASSERT_TRUE(response->headers); |
| 12989 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12990 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12991 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12992 | |
| 12993 | std::string response_data; |
| 12994 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12995 | EXPECT_EQ("hello world", response_data); |
| 12996 | |
| 12997 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12998 | http_server_properties |
| 12999 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13000 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13001 | } |
| 13002 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13003 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13004 | MockRead data_reads[] = { |
| 13005 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13006 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13007 | MockRead("\r\n"), |
| 13008 | MockRead("hello world"), |
| 13009 | MockRead(SYNCHRONOUS, OK), |
| 13010 | }; |
| 13011 | |
| 13012 | HttpRequestInfo request; |
| 13013 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13014 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13015 | request.traffic_annotation = |
| 13016 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13017 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13018 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13020 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13021 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13022 | ssl.ssl_info.cert = |
| 13023 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13024 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13025 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13026 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13027 | TestCompletionCallback callback; |
| 13028 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13029 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13032 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13034 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13035 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13036 | HttpServerProperties* http_server_properties = |
| 13037 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13038 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13039 | http_server_properties |
| 13040 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13041 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13042 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13043 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13045 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13046 | ASSERT_TRUE(response); |
| 13047 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13048 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13049 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13050 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13051 | |
| 13052 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13053 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13054 | EXPECT_EQ("hello world", response_data); |
| 13055 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13056 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13057 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 13058 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13059 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 13060 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 13061 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13062 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13063 | } |
| 13064 | |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13065 | TEST_F(HttpNetworkTransactionTest, |
| 13066 | HonorAlternativeServiceHeaderWithNetworkIsolationKey) { |
| 13067 | base::test::ScopedFeatureList feature_list; |
| 13068 | feature_list.InitWithFeatures( |
| 13069 | // enabled_features |
| 13070 | {features::kPartitionHttpServerPropertiesByNetworkIsolationKey, |
| 13071 | // Need to partition connections by NetworkIsolationKey for |
| 13072 | // SpdySessionKeys to include NetworkIsolationKeys. |
| 13073 | features::kPartitionConnectionsByNetworkIsolationKey}, |
| 13074 | // disabled_features |
| 13075 | {}); |
| 13076 | // Since HttpServerProperties caches the feature value, have to create a new |
| 13077 | // one. |
| 13078 | session_deps_.http_server_properties = |
| 13079 | std::make_unique<HttpServerProperties>(); |
| 13080 | |
| 13081 | const url::Origin kOrigin1 = url::Origin::Create(GURL("https://foo.test/")); |
| 13082 | const net::NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 13083 | const url::Origin kOrigin2 = url::Origin::Create(GURL("https://bar.test/")); |
| 13084 | const net::NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
| 13085 | |
| 13086 | MockRead data_reads[] = { |
| 13087 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13088 | MockRead(kAlternativeServiceHttpHeader), |
| 13089 | MockRead("\r\n"), |
| 13090 | MockRead("hello world"), |
| 13091 | MockRead(SYNCHRONOUS, OK), |
| 13092 | }; |
| 13093 | |
| 13094 | HttpRequestInfo request; |
| 13095 | request.method = "GET"; |
| 13096 | request.url = GURL("https://www.example.org/"); |
| 13097 | request.traffic_annotation = |
| 13098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 13099 | request.network_isolation_key = kNetworkIsolationKey1; |
| 13100 | |
| 13101 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 13102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13103 | |
| 13104 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13105 | ssl.ssl_info.cert = |
| 13106 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13107 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 13108 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13109 | |
| 13110 | TestCompletionCallback callback; |
| 13111 | |
| 13112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13113 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13114 | |
| 13115 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 13116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13117 | |
| 13118 | url::SchemeHostPort test_server(request.url); |
| 13119 | HttpServerProperties* http_server_properties = |
| 13120 | session->http_server_properties(); |
| 13121 | EXPECT_TRUE( |
| 13122 | http_server_properties |
| 13123 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey1) |
| 13124 | .empty()); |
| 13125 | |
| 13126 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13127 | |
| 13128 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13129 | ASSERT_TRUE(response); |
| 13130 | ASSERT_TRUE(response->headers); |
| 13131 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13132 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13133 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 13134 | |
| 13135 | std::string response_data; |
| 13136 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13137 | EXPECT_EQ("hello world", response_data); |
| 13138 | |
| 13139 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 13140 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 13141 | kNetworkIsolationKey1); |
| 13142 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 13143 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 13144 | EXPECT_EQ(alternative_service, |
| 13145 | alternative_service_info_vector[0].alternative_service()); |
| 13146 | |
| 13147 | // Make sure the alternative service information is only associated with |
| 13148 | // kNetworkIsolationKey1. |
| 13149 | EXPECT_TRUE( |
| 13150 | http_server_properties |
| 13151 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13152 | .empty()); |
| 13153 | EXPECT_TRUE( |
| 13154 | http_server_properties |
| 13155 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey2) |
| 13156 | .empty()); |
| 13157 | } |
| 13158 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13159 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13160 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13161 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13162 | MockRead data_reads[] = { |
| 13163 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13164 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13165 | MockRead("\r\n"), |
| 13166 | MockRead("hello world"), |
| 13167 | MockRead(SYNCHRONOUS, OK), |
| 13168 | }; |
| 13169 | |
| 13170 | HttpRequestInfo request; |
| 13171 | request.method = "GET"; |
| 13172 | request.url = GURL("http://www.example.org/"); |
| 13173 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13174 | request.traffic_annotation = |
| 13175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13176 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13177 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13179 | |
| 13180 | TestCompletionCallback callback; |
| 13181 | |
| 13182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13183 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13184 | |
| 13185 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13186 | HttpServerProperties* http_server_properties = |
| 13187 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13188 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13189 | http_server_properties |
| 13190 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13191 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13192 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13193 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13195 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13196 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13197 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13198 | ASSERT_TRUE(response); |
| 13199 | ASSERT_TRUE(response->headers); |
| 13200 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13201 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13202 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13203 | |
| 13204 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13205 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13206 | EXPECT_EQ("hello world", response_data); |
| 13207 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13208 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13209 | http_server_properties |
| 13210 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13211 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13212 | } |
| 13213 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 13214 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13215 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13216 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13217 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 13218 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13219 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13220 | HttpRequestInfo request; |
| 13221 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13222 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13223 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13224 | request.traffic_annotation = |
| 13225 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13226 | |
| 13227 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13228 | StaticSocketDataProvider first_data; |
| 13229 | first_data.set_connect_data(mock_connect); |
| 13230 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13231 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13232 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13234 | |
| 13235 | MockRead data_reads[] = { |
| 13236 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 13237 | MockRead(ASYNC, OK), |
| 13238 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13239 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13240 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 13241 | |
| 13242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13243 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13244 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13245 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13246 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 13247 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13248 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13249 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13250 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13251 | alternative_service, expiration); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13254 | TestCompletionCallback callback; |
| 13255 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13256 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13257 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13258 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13259 | } |
| 13260 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13261 | // Regression test for https://crbug.com/615497: |
| 13262 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13263 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13264 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13265 | HttpRequestInfo request; |
| 13266 | request.method = "GET"; |
| 13267 | request.url = GURL("http://www.example.org/"); |
| 13268 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13269 | request.traffic_annotation = |
| 13270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13271 | |
| 13272 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13273 | StaticSocketDataProvider first_data; |
| 13274 | first_data.set_connect_data(mock_connect); |
| 13275 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 13276 | |
| 13277 | MockRead data_reads[] = { |
| 13278 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 13279 | MockRead(ASYNC, OK), |
| 13280 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13281 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13282 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 13283 | |
| 13284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13285 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13286 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13287 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13288 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13289 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13290 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13291 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13292 | alternative_service, expiration); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13294 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13295 | TestCompletionCallback callback; |
| 13296 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13297 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13298 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13299 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13300 | } |
| 13301 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13302 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13303 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13305 | HttpServerProperties* http_server_properties = |
| 13306 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13307 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13308 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13309 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13310 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13311 | test_server, NetworkIsolationKey(), alternative_service, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13312 | session->context().quic_context->params()->supported_versions); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13313 | EXPECT_EQ(1u, |
| 13314 | http_server_properties |
| 13315 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13316 | .size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13317 | |
| 13318 | // Send a clear header. |
| 13319 | MockRead data_reads[] = { |
| 13320 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13321 | MockRead("Alt-Svc: clear\r\n"), |
| 13322 | MockRead("\r\n"), |
| 13323 | MockRead("hello world"), |
| 13324 | MockRead(SYNCHRONOUS, OK), |
| 13325 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13326 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13328 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13329 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13330 | ssl.ssl_info.cert = |
| 13331 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13332 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13334 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13335 | HttpRequestInfo request; |
| 13336 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13337 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13338 | request.traffic_annotation = |
| 13339 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13340 | |
| 13341 | TestCompletionCallback callback; |
| 13342 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13343 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13344 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13345 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13346 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13347 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13348 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13349 | ASSERT_TRUE(response); |
| 13350 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13351 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13352 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13353 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13354 | |
| 13355 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13356 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13357 | EXPECT_EQ("hello world", response_data); |
| 13358 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13359 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13360 | http_server_properties |
| 13361 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13362 | .empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13363 | } |
| 13364 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13365 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13366 | MockRead data_reads[] = { |
| 13367 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13368 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 13369 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13370 | MockRead("hello world"), |
| 13371 | MockRead(SYNCHRONOUS, OK), |
| 13372 | }; |
| 13373 | |
| 13374 | HttpRequestInfo request; |
| 13375 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13376 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13377 | request.traffic_annotation = |
| 13378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13379 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13380 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13381 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13382 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13383 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13384 | ssl.ssl_info.cert = |
| 13385 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13386 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13387 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13388 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13389 | TestCompletionCallback callback; |
| 13390 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13393 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13394 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13395 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13396 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13397 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13398 | HttpServerProperties* http_server_properties = |
| 13399 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13400 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13401 | http_server_properties |
| 13402 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13403 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13404 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13405 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13408 | ASSERT_TRUE(response); |
| 13409 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13410 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13411 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13412 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13413 | |
| 13414 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13415 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13416 | EXPECT_EQ("hello world", response_data); |
| 13417 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13418 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13419 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 13420 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13421 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 13422 | |
| 13423 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 13424 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13425 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13426 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 13427 | 1234); |
| 13428 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13429 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13430 | } |
| 13431 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13432 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13433 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13434 | HostPortPair alternative("alternative.example.org", 443); |
| 13435 | std::string origin_url = "https://origin.example.org:443"; |
| 13436 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13437 | |
| 13438 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13439 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13440 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13441 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13442 | |
| 13443 | // HTTP/1.1 data for request. |
| 13444 | MockWrite http_writes[] = { |
| 13445 | MockWrite("GET / HTTP/1.1\r\n" |
| 13446 | "Host: alternative.example.org\r\n" |
| 13447 | "Connection: keep-alive\r\n\r\n"), |
| 13448 | }; |
| 13449 | |
| 13450 | MockRead http_reads[] = { |
| 13451 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13452 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13453 | "Content-Length: 40\r\n\r\n" |
| 13454 | "first HTTP/1.1 response from alternative"), |
| 13455 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13456 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13457 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13458 | |
| 13459 | StaticSocketDataProvider data_refused; |
| 13460 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13461 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13462 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13463 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13465 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13466 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13467 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13468 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13469 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13470 | server, NetworkIsolationKey(), alternative_service, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13471 | DefaultSupportedQuicVersions()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13472 | // Mark the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 13473 | http_server_properties->MarkAlternativeServiceBroken(alternative_service, |
| 13474 | NetworkIsolationKey()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13475 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13476 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13478 | request.method = "GET"; |
| 13479 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13480 | request.traffic_annotation = |
| 13481 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 13482 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13483 | TestCompletionCallback callback; |
| 13484 | NetErrorDetails details; |
| 13485 | EXPECT_FALSE(details.quic_broken); |
| 13486 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13487 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13488 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13489 | EXPECT_TRUE(details.quic_broken); |
| 13490 | } |
| 13491 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13492 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13493 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13494 | HostPortPair alternative1("alternative1.example.org", 443); |
| 13495 | HostPortPair alternative2("alternative2.example.org", 443); |
| 13496 | std::string origin_url = "https://origin.example.org:443"; |
| 13497 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 13498 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 13499 | |
| 13500 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 13501 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13502 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13504 | |
| 13505 | // HTTP/1.1 data for request. |
| 13506 | MockWrite http_writes[] = { |
| 13507 | MockWrite("GET / HTTP/1.1\r\n" |
| 13508 | "Host: alternative1.example.org\r\n" |
| 13509 | "Connection: keep-alive\r\n\r\n"), |
| 13510 | }; |
| 13511 | |
| 13512 | MockRead http_reads[] = { |
| 13513 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13514 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13515 | "Content-Length: 40\r\n\r\n" |
| 13516 | "first HTTP/1.1 response from alternative1"), |
| 13517 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13518 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13519 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13520 | |
| 13521 | StaticSocketDataProvider data_refused; |
| 13522 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13523 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13526 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13527 | session->http_server_properties(); |
| 13528 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13529 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13530 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 13531 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 13532 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13533 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13534 | alternative_service_info_vector.push_back( |
| 13535 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 13536 | alternative_service1, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13537 | session->context().quic_context->params()->supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13538 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13539 | alternative_service_info_vector.push_back( |
| 13540 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 13541 | alternative_service2, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13542 | session->context().quic_context->params()->supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13543 | |
| 13544 | http_server_properties->SetAlternativeServices( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13545 | server, NetworkIsolationKey(), alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13546 | |
| 13547 | // Mark one of the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 13548 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1, |
| 13549 | NetworkIsolationKey()); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13550 | EXPECT_EQ(2u, http_server_properties |
| 13551 | ->GetAlternativeServiceInfos(server, NetworkIsolationKey()) |
| 13552 | .size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13553 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13554 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13556 | request.method = "GET"; |
| 13557 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13558 | request.traffic_annotation = |
| 13559 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 13560 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13561 | TestCompletionCallback callback; |
| 13562 | NetErrorDetails details; |
| 13563 | EXPECT_FALSE(details.quic_broken); |
| 13564 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13565 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13566 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13567 | EXPECT_FALSE(details.quic_broken); |
| 13568 | } |
| 13569 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13570 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13571 | HttpRequestInfo request; |
| 13572 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13573 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13574 | request.traffic_annotation = |
| 13575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13576 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13577 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13578 | StaticSocketDataProvider first_data; |
| 13579 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13580 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13581 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13582 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13584 | |
| 13585 | MockRead data_reads[] = { |
| 13586 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13587 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13588 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13589 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13590 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13591 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13592 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13594 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13595 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13596 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13597 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13598 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 13599 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13600 | // Port is ignored by MockConnect anyway. |
| 13601 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13602 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13603 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13604 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13605 | server, NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13606 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13608 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13612 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13613 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13614 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13615 | ASSERT_TRUE(response); |
| 13616 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13617 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13618 | |
| 13619 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13620 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13621 | EXPECT_EQ("hello world", response_data); |
| 13622 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13623 | const AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13624 | http_server_properties->GetAlternativeServiceInfos(server, |
| 13625 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13626 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 13627 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13628 | alternative_service_info_vector[0].alternative_service()); |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 13629 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 13630 | alternative_service, NetworkIsolationKey())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13631 | } |
| 13632 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13633 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13634 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13635 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13636 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13637 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13638 | HttpRequestInfo restricted_port_request; |
| 13639 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13640 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13641 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13642 | restricted_port_request.traffic_annotation = |
| 13643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13644 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13645 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13646 | StaticSocketDataProvider first_data; |
| 13647 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13648 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13649 | |
| 13650 | MockRead data_reads[] = { |
| 13651 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13652 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13653 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13654 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13655 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13656 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13657 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13658 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13662 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13663 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13664 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13665 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13666 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13667 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13668 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13669 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13670 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13671 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13674 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13676 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 13677 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13679 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13680 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13681 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13682 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13683 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 13684 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 13685 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13686 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13687 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13688 | |
| 13689 | HttpRequestInfo restricted_port_request; |
| 13690 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13691 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13692 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13693 | restricted_port_request.traffic_annotation = |
| 13694 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13695 | |
| 13696 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13697 | StaticSocketDataProvider first_data; |
| 13698 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13699 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13700 | |
| 13701 | MockRead data_reads[] = { |
| 13702 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13703 | MockRead("hello world"), |
| 13704 | MockRead(ASYNC, OK), |
| 13705 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13706 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13707 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13708 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13709 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13713 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13714 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13715 | session->http_server_properties(); |
| 13716 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13717 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13718 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13719 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13720 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13721 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13722 | alternative_service, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13725 | TestCompletionCallback callback; |
| 13726 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13727 | EXPECT_EQ(ERR_IO_PENDING, |
| 13728 | trans.Start(&restricted_port_request, callback.callback(), |
| 13729 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13730 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13731 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13732 | } |
| 13733 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13734 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13735 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13736 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13737 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13738 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13739 | HttpRequestInfo restricted_port_request; |
| 13740 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13741 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13742 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13743 | restricted_port_request.traffic_annotation = |
| 13744 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13745 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13746 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13747 | StaticSocketDataProvider first_data; |
| 13748 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13749 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13750 | |
| 13751 | MockRead data_reads[] = { |
| 13752 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13753 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13754 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13755 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13756 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13757 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13758 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13759 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13761 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13763 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13764 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13765 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13766 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13767 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13768 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13769 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13770 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13771 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13772 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13775 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13776 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13777 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 13778 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13780 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13781 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13782 | } |
| 13783 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13784 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13785 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13786 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13787 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13788 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13789 | HttpRequestInfo unrestricted_port_request; |
| 13790 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13791 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13792 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13793 | unrestricted_port_request.traffic_annotation = |
| 13794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13795 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13796 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13797 | StaticSocketDataProvider first_data; |
| 13798 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13799 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13800 | |
| 13801 | MockRead data_reads[] = { |
| 13802 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13803 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13804 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13805 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13806 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13807 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13808 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13809 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13813 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13814 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13815 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13816 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13817 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13818 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13819 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13820 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13821 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 13822 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13825 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13827 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13828 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13830 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13831 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13832 | } |
| 13833 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13834 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13835 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13836 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13837 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13838 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13839 | HttpRequestInfo unrestricted_port_request; |
| 13840 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13841 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13842 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13843 | unrestricted_port_request.traffic_annotation = |
| 13844 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13845 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13846 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13847 | StaticSocketDataProvider first_data; |
| 13848 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13849 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13850 | |
| 13851 | MockRead data_reads[] = { |
| 13852 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13853 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13854 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13855 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13856 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13857 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13858 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13859 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13863 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13864 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13865 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 13866 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13867 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13868 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13869 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13870 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13871 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 13872 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13875 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13877 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13878 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13879 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13880 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13881 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13882 | } |
| 13883 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13884 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 13885 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 13886 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13887 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13888 | HttpRequestInfo request; |
| 13889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13890 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13891 | request.traffic_annotation = |
| 13892 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13893 | |
| 13894 | // The alternate protocol request will error out before we attempt to connect, |
| 13895 | // so only the standard HTTP request will try to connect. |
| 13896 | MockRead data_reads[] = { |
| 13897 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13898 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13899 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13900 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13901 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13902 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13903 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13904 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13905 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13906 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13907 | session->http_server_properties(); |
| 13908 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13909 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13910 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13911 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13912 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13913 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13914 | alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13917 | TestCompletionCallback callback; |
| 13918 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13919 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13921 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13922 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13924 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13925 | ASSERT_TRUE(response); |
| 13926 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13927 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13928 | |
| 13929 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13930 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13931 | EXPECT_EQ("hello world", response_data); |
| 13932 | } |
| 13933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13934 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13935 | HttpRequestInfo request; |
| 13936 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13937 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13938 | request.traffic_annotation = |
| 13939 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13940 | |
| 13941 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13942 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13943 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13944 | MockRead("\r\n"), |
| 13945 | MockRead("hello world"), |
| 13946 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13947 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13948 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13949 | StaticSocketDataProvider first_transaction(data_reads, |
| 13950 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13951 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13952 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13953 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13955 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13956 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13957 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13958 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13959 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13960 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13961 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13962 | spdy::SpdySerializedFrame resp( |
| 13963 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13964 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13965 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13966 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13967 | }; |
| 13968 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13969 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13970 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13971 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13972 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13973 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13974 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13975 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13976 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13977 | &hanging_non_alternate_protocol_socket); |
| 13978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13979 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13980 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13982 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13983 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13984 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13985 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13987 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13988 | |
| 13989 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13990 | ASSERT_TRUE(response); |
| 13991 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13992 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13993 | |
| 13994 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13995 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13996 | EXPECT_EQ("hello world", response_data); |
| 13997 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13998 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13999 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14000 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14001 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14003 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14004 | |
| 14005 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14006 | ASSERT_TRUE(response); |
| 14007 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14008 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14009 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14010 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14011 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14012 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14013 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14014 | } |
| 14015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14016 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14017 | HttpRequestInfo request; |
| 14018 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14019 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14020 | request.traffic_annotation = |
| 14021 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14022 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14023 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14024 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14025 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14026 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14027 | MockRead("\r\n"), |
| 14028 | MockRead("hello world"), |
| 14029 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14030 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14031 | }; |
| 14032 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14033 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14034 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14035 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14036 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 14037 | ssl_http11.ssl_info.cert = |
| 14038 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 14039 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 14041 | |
| 14042 | // Second transaction starts an alternative and a non-alternative Job. |
| 14043 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14044 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14045 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14046 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14047 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 14048 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14049 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14050 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 14051 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14052 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14053 | // Third transaction starts an alternative and a non-alternative job. |
| 14054 | // The non-alternative job hangs, but the alternative one succeeds. |
| 14055 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14056 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14057 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14058 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14059 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14060 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14061 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14062 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14063 | spdy::SpdySerializedFrame resp1( |
| 14064 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14065 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14066 | spdy::SpdySerializedFrame resp2( |
| 14067 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14068 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14069 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14070 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 14071 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14072 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14073 | }; |
| 14074 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14075 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14076 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14077 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14078 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14079 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14080 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14081 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 14082 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14085 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14086 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14088 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14090 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14091 | |
| 14092 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14093 | ASSERT_TRUE(response); |
| 14094 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14095 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14096 | |
| 14097 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14098 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14099 | EXPECT_EQ("hello world", response_data); |
| 14100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14101 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14102 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14103 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14106 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14107 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14108 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14109 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14110 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14111 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 14112 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14113 | |
| 14114 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14115 | ASSERT_TRUE(response); |
| 14116 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14117 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14118 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14119 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14120 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14121 | EXPECT_EQ("hello!", response_data); |
| 14122 | |
| 14123 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14124 | ASSERT_TRUE(response); |
| 14125 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14126 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14127 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14128 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14129 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14130 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14131 | } |
| 14132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14133 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 14134 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 14135 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14136 | HttpRequestInfo request; |
| 14137 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14138 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14139 | request.traffic_annotation = |
| 14140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14141 | |
| 14142 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14143 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14144 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14145 | MockRead("\r\n"), |
| 14146 | MockRead("hello world"), |
| 14147 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14148 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14149 | }; |
| 14150 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14151 | StaticSocketDataProvider first_transaction(data_reads, |
| 14152 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14153 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14154 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14155 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 14156 | ssl.ssl_info.cert = |
| 14157 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 14158 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14159 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14160 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14161 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14162 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14163 | hanging_alternate_protocol_socket.set_connect_data( |
| 14164 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14165 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14166 | &hanging_alternate_protocol_socket); |
| 14167 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14168 | // 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] | 14169 | StaticSocketDataProvider second_transaction(data_reads, |
| 14170 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14171 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14174 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14177 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14178 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14179 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14180 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14181 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14182 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14183 | |
| 14184 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14185 | ASSERT_TRUE(response); |
| 14186 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14187 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14188 | |
| 14189 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14190 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14191 | EXPECT_EQ("hello world", response_data); |
| 14192 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14193 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14194 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14195 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14196 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14198 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14199 | |
| 14200 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14201 | ASSERT_TRUE(response); |
| 14202 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14203 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14204 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14205 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14206 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14207 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14208 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14209 | } |
| 14210 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14211 | // Test that proxy is resolved using the origin url, |
| 14212 | // regardless of the alternative server. |
| 14213 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 14214 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 14215 | ProxyConfig proxy_config; |
| 14216 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 14217 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14218 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 14219 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14220 | |
| 14221 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14222 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14223 | &capturing_proxy_resolver); |
| 14224 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 14225 | RecordingTestNetLog net_log; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14226 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14227 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 14228 | std::make_unique<ConfiguredProxyResolutionService>( |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14229 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 14230 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14231 | |
| 14232 | session_deps_.net_log = &net_log; |
| 14233 | |
| 14234 | // Configure alternative service with a hostname that is not bypassed by the |
| 14235 | // proxy. |
| 14236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14237 | HttpServerProperties* http_server_properties = |
| 14238 | session->http_server_properties(); |
| 14239 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14240 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14241 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14242 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14243 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 14244 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14245 | |
| 14246 | // Non-alternative job should hang. |
| 14247 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14248 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14249 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 14250 | session_deps_.socket_factory->AddSocketDataProvider( |
| 14251 | &hanging_alternate_protocol_socket); |
| 14252 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14253 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14254 | |
| 14255 | HttpRequestInfo request; |
| 14256 | request.method = "GET"; |
| 14257 | request.url = GURL("https://www.example.org/"); |
| 14258 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14259 | request.traffic_annotation = |
| 14260 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14261 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14262 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14263 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 14264 | |
| 14265 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 14266 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14267 | spdy::SpdySerializedFrame resp( |
| 14268 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14269 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14270 | MockRead spdy_reads[] = { |
| 14271 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 14272 | }; |
| 14273 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14274 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14275 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 14276 | |
| 14277 | TestCompletionCallback callback; |
| 14278 | |
| 14279 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14280 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14281 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14282 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 14283 | |
| 14284 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 14285 | ASSERT_TRUE(response); |
| 14286 | ASSERT_TRUE(response->headers); |
| 14287 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14288 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14289 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14290 | |
| 14291 | std::string response_data; |
| 14292 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 14293 | EXPECT_EQ("hello!", response_data); |
| 14294 | |
| 14295 | // Origin host bypasses proxy, no resolution should have happened. |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14296 | ASSERT_TRUE(capturing_proxy_resolver.lookup_info().empty()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14297 | } |
| 14298 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14299 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14300 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 14301 | proxy_config.set_auto_detect(true); |
| 14302 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 14303 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 14304 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14305 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 14306 | std::make_unique<ConfiguredProxyResolutionService>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14307 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 14308 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 14309 | std::make_unique<CapturingProxyResolverFactory>( |
| 14310 | &capturing_proxy_resolver), |
| 14311 | nullptr); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 14312 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14313 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14314 | |
| 14315 | HttpRequestInfo request; |
| 14316 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14317 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14318 | request.traffic_annotation = |
| 14319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14320 | |
| 14321 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14322 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14323 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14324 | MockRead("\r\n"), |
| 14325 | MockRead("hello world"), |
| 14326 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14327 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14328 | }; |
| 14329 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14330 | StaticSocketDataProvider first_transaction(data_reads, |
| 14331 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14332 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14333 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14334 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14336 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14337 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14338 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14339 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14340 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14341 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14342 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14343 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14344 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14345 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14346 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14347 | }; |
| 14348 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 14349 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 14350 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14351 | spdy::SpdySerializedFrame resp( |
| 14352 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14353 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14354 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14355 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 14356 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14357 | }; |
| 14358 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14359 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14360 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14361 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14362 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14363 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14364 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 14365 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14366 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14367 | &hanging_non_alternate_protocol_socket); |
| 14368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14369 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14372 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14373 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14374 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14375 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 14376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14377 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 14378 | |
| 14379 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14380 | ASSERT_TRUE(response); |
| 14381 | ASSERT_TRUE(response->headers); |
| 14382 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 14383 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14384 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 14385 | |
| 14386 | std::string response_data; |
| 14387 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 14388 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14389 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14390 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14391 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14393 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14395 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14396 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 14397 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14398 | ASSERT_TRUE(response); |
| 14399 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14400 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14401 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14402 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14403 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14404 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14405 | EXPECT_EQ("hello!", response_data); |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14406 | ASSERT_EQ(2u, capturing_proxy_resolver.lookup_info().size()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14407 | EXPECT_EQ("https://www.example.org/", |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14408 | capturing_proxy_resolver.lookup_info()[0].url.spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14409 | EXPECT_EQ("https://www.example.org/", |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14410 | capturing_proxy_resolver.lookup_info()[1].url.spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14411 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14412 | LoadTimingInfo load_timing_info; |
| 14413 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 14414 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14415 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14416 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14417 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14418 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 14419 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14420 | HttpRequestInfo request; |
| 14421 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14422 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14423 | request.traffic_annotation = |
| 14424 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14425 | |
| 14426 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14427 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14428 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14429 | MockRead("\r\n"), |
| 14430 | MockRead("hello world"), |
| 14431 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14432 | }; |
| 14433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14434 | StaticSocketDataProvider first_transaction(data_reads, |
| 14435 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14436 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14437 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14438 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14440 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14441 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14442 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14443 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14444 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14445 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14446 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14447 | spdy::SpdySerializedFrame resp( |
| 14448 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14449 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14450 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14451 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14452 | }; |
| 14453 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14454 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14455 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14456 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 14457 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14458 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14460 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14461 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14462 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14463 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14464 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14465 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14466 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14467 | |
| 14468 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14469 | ASSERT_TRUE(response); |
| 14470 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14471 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14472 | |
| 14473 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14474 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14475 | EXPECT_EQ("hello world", response_data); |
| 14476 | |
| 14477 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14478 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14479 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 14480 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 14481 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 14482 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14483 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14484 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 14485 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14486 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14487 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14488 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14489 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14491 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14492 | |
| 14493 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14494 | ASSERT_TRUE(response); |
| 14495 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14496 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14497 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14498 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14499 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14500 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14501 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 14502 | } |
| 14503 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14504 | // GenerateAuthToken is a mighty big test. |
| 14505 | // It tests all permutation of GenerateAuthToken behavior: |
| 14506 | // - Synchronous and Asynchronous completion. |
| 14507 | // - OK or error on completion. |
| 14508 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 14509 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 14510 | // - Non-authenticating and authenticating backend. |
| 14511 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 14512 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14513 | // problems generating an auth token for an authenticating proxy, we don't |
| 14514 | // need to test all permutations of the backend server). |
| 14515 | // |
| 14516 | // The test proceeds by going over each of the configuration cases, and |
| 14517 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 14518 | // specifies both the configuration for the test as well as the expectations |
| 14519 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14520 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14521 | static const char kServer[] = "http://www.example.com"; |
| 14522 | static const char kSecureServer[] = "https://www.example.com"; |
| 14523 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14524 | |
| 14525 | enum AuthTiming { |
| 14526 | AUTH_NONE, |
| 14527 | AUTH_SYNC, |
| 14528 | AUTH_ASYNC, |
| 14529 | }; |
| 14530 | |
| 14531 | const MockWrite kGet( |
| 14532 | "GET / HTTP/1.1\r\n" |
| 14533 | "Host: www.example.com\r\n" |
| 14534 | "Connection: keep-alive\r\n\r\n"); |
| 14535 | const MockWrite kGetProxy( |
| 14536 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14537 | "Host: www.example.com\r\n" |
| 14538 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 14539 | const MockWrite kGetAuth( |
| 14540 | "GET / HTTP/1.1\r\n" |
| 14541 | "Host: www.example.com\r\n" |
| 14542 | "Connection: keep-alive\r\n" |
| 14543 | "Authorization: auth_token\r\n\r\n"); |
| 14544 | const MockWrite kGetProxyAuth( |
| 14545 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14546 | "Host: www.example.com\r\n" |
| 14547 | "Proxy-Connection: keep-alive\r\n" |
| 14548 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 14549 | const MockWrite kGetAuthThroughProxy( |
| 14550 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14551 | "Host: www.example.com\r\n" |
| 14552 | "Proxy-Connection: keep-alive\r\n" |
| 14553 | "Authorization: auth_token\r\n\r\n"); |
| 14554 | const MockWrite kGetAuthWithProxyAuth( |
| 14555 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14556 | "Host: www.example.com\r\n" |
| 14557 | "Proxy-Connection: keep-alive\r\n" |
| 14558 | "Proxy-Authorization: auth_token\r\n" |
| 14559 | "Authorization: auth_token\r\n\r\n"); |
| 14560 | const MockWrite kConnect( |
| 14561 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14562 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14563 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 14564 | const MockWrite kConnectProxyAuth( |
| 14565 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14566 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14567 | "Proxy-Connection: keep-alive\r\n" |
| 14568 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 14569 | |
| 14570 | const MockRead kSuccess( |
| 14571 | "HTTP/1.1 200 OK\r\n" |
| 14572 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14573 | "Content-Length: 3\r\n\r\n" |
| 14574 | "Yes"); |
| 14575 | const MockRead kFailure( |
| 14576 | "Should not be called."); |
| 14577 | const MockRead kServerChallenge( |
| 14578 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14579 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14580 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14581 | "Content-Length: 14\r\n\r\n" |
| 14582 | "Unauthorized\r\n"); |
| 14583 | const MockRead kProxyChallenge( |
| 14584 | "HTTP/1.1 407 Unauthorized\r\n" |
| 14585 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 14586 | "Proxy-Connection: close\r\n" |
| 14587 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14588 | "Content-Length: 14\r\n\r\n" |
| 14589 | "Unauthorized\r\n"); |
| 14590 | const MockRead kProxyConnected( |
| 14591 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 14592 | |
| 14593 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 14594 | // no constructors, but the C++ compiler on Windows warns about |
| 14595 | // unspecified data in compound literals. So, moved to using constructors, |
| 14596 | // and TestRound's created with the default constructor should not be used. |
| 14597 | struct TestRound { |
| 14598 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14599 | : expected_rv(ERR_UNEXPECTED), |
| 14600 | extra_write(nullptr), |
| 14601 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14602 | TestRound(const MockWrite& write_arg, |
| 14603 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14604 | int expected_rv_arg) |
| 14605 | : write(write_arg), |
| 14606 | read(read_arg), |
| 14607 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14608 | extra_write(nullptr), |
| 14609 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14610 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 14611 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 14612 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14613 | : write(write_arg), |
| 14614 | read(read_arg), |
| 14615 | expected_rv(expected_rv_arg), |
| 14616 | extra_write(extra_write_arg), |
| 14617 | extra_read(extra_read_arg) { |
| 14618 | } |
| 14619 | MockWrite write; |
| 14620 | MockRead read; |
| 14621 | int expected_rv; |
| 14622 | const MockWrite* extra_write; |
| 14623 | const MockRead* extra_read; |
| 14624 | }; |
| 14625 | |
| 14626 | static const int kNoSSL = 500; |
| 14627 | |
| 14628 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14629 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14630 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14631 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14632 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14633 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14634 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14635 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14636 | int num_auth_rounds; |
| 14637 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14638 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14639 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14640 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14641 | {__LINE__, |
| 14642 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14643 | AUTH_NONE, |
| 14644 | OK, |
| 14645 | kServer, |
| 14646 | AUTH_NONE, |
| 14647 | OK, |
| 14648 | 1, |
| 14649 | kNoSSL, |
| 14650 | {TestRound(kGet, kSuccess, OK)}}, |
| 14651 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14652 | {__LINE__, |
| 14653 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14654 | AUTH_NONE, |
| 14655 | OK, |
| 14656 | kServer, |
| 14657 | AUTH_SYNC, |
| 14658 | OK, |
| 14659 | 2, |
| 14660 | kNoSSL, |
| 14661 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14662 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14663 | {__LINE__, |
| 14664 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14665 | AUTH_NONE, |
| 14666 | OK, |
| 14667 | kServer, |
| 14668 | AUTH_SYNC, |
| 14669 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14670 | 3, |
| 14671 | kNoSSL, |
| 14672 | {TestRound(kGet, kServerChallenge, OK), |
| 14673 | TestRound(kGet, kServerChallenge, OK), |
| 14674 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14675 | {__LINE__, |
| 14676 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14677 | AUTH_NONE, |
| 14678 | OK, |
| 14679 | kServer, |
| 14680 | AUTH_SYNC, |
| 14681 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14682 | 2, |
| 14683 | kNoSSL, |
| 14684 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14685 | {__LINE__, |
| 14686 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14687 | AUTH_NONE, |
| 14688 | OK, |
| 14689 | kServer, |
| 14690 | AUTH_SYNC, |
| 14691 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 14692 | 2, |
| 14693 | kNoSSL, |
| 14694 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14695 | {__LINE__, |
| 14696 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14697 | AUTH_SYNC, |
| 14698 | ERR_FAILED, |
| 14699 | kServer, |
| 14700 | AUTH_NONE, |
| 14701 | OK, |
| 14702 | 2, |
| 14703 | kNoSSL, |
| 14704 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14705 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14706 | {__LINE__, |
| 14707 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14708 | AUTH_ASYNC, |
| 14709 | ERR_FAILED, |
| 14710 | kServer, |
| 14711 | AUTH_NONE, |
| 14712 | OK, |
| 14713 | 2, |
| 14714 | kNoSSL, |
| 14715 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14716 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14717 | {__LINE__, |
| 14718 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14719 | AUTH_NONE, |
| 14720 | OK, |
| 14721 | kServer, |
| 14722 | AUTH_SYNC, |
| 14723 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14724 | 2, |
| 14725 | kNoSSL, |
| 14726 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14727 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14728 | {__LINE__, |
| 14729 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14730 | AUTH_NONE, |
| 14731 | OK, |
| 14732 | kServer, |
| 14733 | AUTH_ASYNC, |
| 14734 | ERR_FAILED, |
| 14735 | 2, |
| 14736 | kNoSSL, |
| 14737 | {TestRound(kGet, kServerChallenge, OK), |
| 14738 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14739 | {__LINE__, |
| 14740 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14741 | AUTH_NONE, |
| 14742 | OK, |
| 14743 | kServer, |
| 14744 | AUTH_ASYNC, |
| 14745 | OK, |
| 14746 | 2, |
| 14747 | kNoSSL, |
| 14748 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14749 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14750 | {__LINE__, |
| 14751 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14752 | AUTH_NONE, |
| 14753 | OK, |
| 14754 | kServer, |
| 14755 | AUTH_ASYNC, |
| 14756 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14757 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14758 | kNoSSL, |
| 14759 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14760 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 14761 | TestRound(kGet, kServerChallenge, OK), |
| 14762 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14763 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14764 | {__LINE__, |
| 14765 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14766 | AUTH_NONE, |
| 14767 | OK, |
| 14768 | kServer, |
| 14769 | AUTH_NONE, |
| 14770 | OK, |
| 14771 | 1, |
| 14772 | kNoSSL, |
| 14773 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 14774 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14775 | {__LINE__, |
| 14776 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14777 | AUTH_NONE, |
| 14778 | OK, |
| 14779 | kServer, |
| 14780 | AUTH_SYNC, |
| 14781 | OK, |
| 14782 | 2, |
| 14783 | kNoSSL, |
| 14784 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14785 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14786 | {__LINE__, |
| 14787 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14788 | AUTH_NONE, |
| 14789 | OK, |
| 14790 | kServer, |
| 14791 | AUTH_SYNC, |
| 14792 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14793 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14794 | kNoSSL, |
| 14795 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14796 | TestRound(kGetProxy, kServerChallenge, OK), |
| 14797 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14798 | {__LINE__, |
| 14799 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14800 | AUTH_NONE, |
| 14801 | OK, |
| 14802 | kServer, |
| 14803 | AUTH_ASYNC, |
| 14804 | OK, |
| 14805 | 2, |
| 14806 | kNoSSL, |
| 14807 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14808 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14809 | {__LINE__, |
| 14810 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14811 | AUTH_NONE, |
| 14812 | OK, |
| 14813 | kServer, |
| 14814 | AUTH_ASYNC, |
| 14815 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14816 | 2, |
| 14817 | kNoSSL, |
| 14818 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14819 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14820 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14821 | {__LINE__, |
| 14822 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14823 | AUTH_SYNC, |
| 14824 | OK, |
| 14825 | kServer, |
| 14826 | AUTH_NONE, |
| 14827 | OK, |
| 14828 | 2, |
| 14829 | kNoSSL, |
| 14830 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14831 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14832 | {__LINE__, |
| 14833 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14834 | AUTH_SYNC, |
| 14835 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14836 | kServer, |
| 14837 | AUTH_NONE, |
| 14838 | OK, |
| 14839 | 2, |
| 14840 | kNoSSL, |
| 14841 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14842 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14843 | {__LINE__, |
| 14844 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14845 | AUTH_ASYNC, |
| 14846 | OK, |
| 14847 | kServer, |
| 14848 | AUTH_NONE, |
| 14849 | OK, |
| 14850 | 2, |
| 14851 | kNoSSL, |
| 14852 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14853 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14854 | {__LINE__, |
| 14855 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14856 | AUTH_ASYNC, |
| 14857 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14858 | kServer, |
| 14859 | AUTH_NONE, |
| 14860 | OK, |
| 14861 | 2, |
| 14862 | kNoSSL, |
| 14863 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14864 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14865 | {__LINE__, |
| 14866 | kProxy, |
| 14867 | AUTH_ASYNC, |
| 14868 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14869 | kServer, |
| 14870 | AUTH_NONE, |
| 14871 | OK, |
| 14872 | 3, |
| 14873 | kNoSSL, |
| 14874 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14875 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14876 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14877 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14878 | {__LINE__, |
| 14879 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14880 | AUTH_SYNC, |
| 14881 | OK, |
| 14882 | kServer, |
| 14883 | AUTH_SYNC, |
| 14884 | OK, |
| 14885 | 3, |
| 14886 | kNoSSL, |
| 14887 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14888 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14889 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14890 | {__LINE__, |
| 14891 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14892 | AUTH_SYNC, |
| 14893 | OK, |
| 14894 | kServer, |
| 14895 | AUTH_SYNC, |
| 14896 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14897 | 3, |
| 14898 | kNoSSL, |
| 14899 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14900 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14901 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14902 | {__LINE__, |
| 14903 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14904 | AUTH_ASYNC, |
| 14905 | OK, |
| 14906 | kServer, |
| 14907 | AUTH_SYNC, |
| 14908 | OK, |
| 14909 | 3, |
| 14910 | kNoSSL, |
| 14911 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14912 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14913 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14914 | {__LINE__, |
| 14915 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14916 | AUTH_ASYNC, |
| 14917 | OK, |
| 14918 | kServer, |
| 14919 | AUTH_SYNC, |
| 14920 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14921 | 3, |
| 14922 | kNoSSL, |
| 14923 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14924 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14925 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14926 | {__LINE__, |
| 14927 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14928 | AUTH_SYNC, |
| 14929 | OK, |
| 14930 | kServer, |
| 14931 | AUTH_ASYNC, |
| 14932 | OK, |
| 14933 | 3, |
| 14934 | kNoSSL, |
| 14935 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14936 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14937 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14938 | {__LINE__, |
| 14939 | kProxy, |
| 14940 | AUTH_SYNC, |
| 14941 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14942 | kServer, |
| 14943 | AUTH_ASYNC, |
| 14944 | OK, |
| 14945 | 4, |
| 14946 | kNoSSL, |
| 14947 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14948 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14949 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14950 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 14951 | {__LINE__, |
| 14952 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14953 | AUTH_SYNC, |
| 14954 | OK, |
| 14955 | kServer, |
| 14956 | AUTH_ASYNC, |
| 14957 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14958 | 3, |
| 14959 | kNoSSL, |
| 14960 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14961 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14962 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14963 | {__LINE__, |
| 14964 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14965 | AUTH_ASYNC, |
| 14966 | OK, |
| 14967 | kServer, |
| 14968 | AUTH_ASYNC, |
| 14969 | OK, |
| 14970 | 3, |
| 14971 | kNoSSL, |
| 14972 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14973 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14974 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14975 | {__LINE__, |
| 14976 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14977 | AUTH_ASYNC, |
| 14978 | OK, |
| 14979 | kServer, |
| 14980 | AUTH_ASYNC, |
| 14981 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14982 | 3, |
| 14983 | kNoSSL, |
| 14984 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14985 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14986 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14987 | {__LINE__, |
| 14988 | kProxy, |
| 14989 | AUTH_ASYNC, |
| 14990 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14991 | kServer, |
| 14992 | AUTH_ASYNC, |
| 14993 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14994 | 4, |
| 14995 | kNoSSL, |
| 14996 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14997 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14998 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14999 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15000 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15001 | {__LINE__, |
| 15002 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15003 | AUTH_NONE, |
| 15004 | OK, |
| 15005 | kSecureServer, |
| 15006 | AUTH_NONE, |
| 15007 | OK, |
| 15008 | 1, |
| 15009 | 0, |
| 15010 | {TestRound(kGet, kSuccess, OK)}}, |
| 15011 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15012 | {__LINE__, |
| 15013 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15014 | AUTH_NONE, |
| 15015 | OK, |
| 15016 | kSecureServer, |
| 15017 | AUTH_SYNC, |
| 15018 | OK, |
| 15019 | 2, |
| 15020 | 0, |
| 15021 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15022 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15023 | {__LINE__, |
| 15024 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15025 | AUTH_NONE, |
| 15026 | OK, |
| 15027 | kSecureServer, |
| 15028 | AUTH_SYNC, |
| 15029 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15030 | 2, |
| 15031 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15032 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15033 | {__LINE__, |
| 15034 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15035 | AUTH_NONE, |
| 15036 | OK, |
| 15037 | kSecureServer, |
| 15038 | AUTH_ASYNC, |
| 15039 | OK, |
| 15040 | 2, |
| 15041 | 0, |
| 15042 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15043 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15044 | {__LINE__, |
| 15045 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15046 | AUTH_NONE, |
| 15047 | OK, |
| 15048 | kSecureServer, |
| 15049 | AUTH_ASYNC, |
| 15050 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15051 | 2, |
| 15052 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15053 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15054 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15055 | {__LINE__, |
| 15056 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15057 | AUTH_NONE, |
| 15058 | OK, |
| 15059 | kSecureServer, |
| 15060 | AUTH_NONE, |
| 15061 | OK, |
| 15062 | 1, |
| 15063 | 0, |
| 15064 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 15065 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15066 | {__LINE__, |
| 15067 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15068 | AUTH_NONE, |
| 15069 | OK, |
| 15070 | kSecureServer, |
| 15071 | AUTH_SYNC, |
| 15072 | OK, |
| 15073 | 2, |
| 15074 | 0, |
| 15075 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15076 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15077 | {__LINE__, |
| 15078 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15079 | AUTH_NONE, |
| 15080 | OK, |
| 15081 | kSecureServer, |
| 15082 | AUTH_SYNC, |
| 15083 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15084 | 2, |
| 15085 | 0, |
| 15086 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15087 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15088 | {__LINE__, |
| 15089 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15090 | AUTH_NONE, |
| 15091 | OK, |
| 15092 | kSecureServer, |
| 15093 | AUTH_ASYNC, |
| 15094 | OK, |
| 15095 | 2, |
| 15096 | 0, |
| 15097 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15098 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15099 | {__LINE__, |
| 15100 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15101 | AUTH_NONE, |
| 15102 | OK, |
| 15103 | kSecureServer, |
| 15104 | AUTH_ASYNC, |
| 15105 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15106 | 2, |
| 15107 | 0, |
| 15108 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15109 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15110 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15111 | {__LINE__, |
| 15112 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15113 | AUTH_SYNC, |
| 15114 | OK, |
| 15115 | kSecureServer, |
| 15116 | AUTH_NONE, |
| 15117 | OK, |
| 15118 | 2, |
| 15119 | 1, |
| 15120 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15121 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15122 | {__LINE__, |
| 15123 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15124 | AUTH_SYNC, |
| 15125 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15126 | kSecureServer, |
| 15127 | AUTH_NONE, |
| 15128 | OK, |
| 15129 | 2, |
| 15130 | kNoSSL, |
| 15131 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15132 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15133 | {__LINE__, |
| 15134 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15135 | AUTH_SYNC, |
| 15136 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 15137 | kSecureServer, |
| 15138 | AUTH_NONE, |
| 15139 | OK, |
| 15140 | 2, |
| 15141 | kNoSSL, |
| 15142 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15143 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15144 | {__LINE__, |
| 15145 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15146 | AUTH_SYNC, |
| 15147 | ERR_UNEXPECTED, |
| 15148 | kSecureServer, |
| 15149 | AUTH_NONE, |
| 15150 | OK, |
| 15151 | 2, |
| 15152 | kNoSSL, |
| 15153 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15154 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15155 | {__LINE__, |
| 15156 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15157 | AUTH_ASYNC, |
| 15158 | OK, |
| 15159 | kSecureServer, |
| 15160 | AUTH_NONE, |
| 15161 | OK, |
| 15162 | 2, |
| 15163 | 1, |
| 15164 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15165 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15166 | {__LINE__, |
| 15167 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15168 | AUTH_ASYNC, |
| 15169 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15170 | kSecureServer, |
| 15171 | AUTH_NONE, |
| 15172 | OK, |
| 15173 | 2, |
| 15174 | kNoSSL, |
| 15175 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15176 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15177 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15178 | {__LINE__, |
| 15179 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15180 | AUTH_SYNC, |
| 15181 | OK, |
| 15182 | kSecureServer, |
| 15183 | AUTH_SYNC, |
| 15184 | OK, |
| 15185 | 3, |
| 15186 | 1, |
| 15187 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15188 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15189 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15190 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15191 | {__LINE__, |
| 15192 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15193 | AUTH_SYNC, |
| 15194 | OK, |
| 15195 | kSecureServer, |
| 15196 | AUTH_SYNC, |
| 15197 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15198 | 3, |
| 15199 | 1, |
| 15200 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15201 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15202 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15203 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15204 | {__LINE__, |
| 15205 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15206 | AUTH_ASYNC, |
| 15207 | OK, |
| 15208 | kSecureServer, |
| 15209 | AUTH_SYNC, |
| 15210 | OK, |
| 15211 | 3, |
| 15212 | 1, |
| 15213 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15214 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15215 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15216 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15217 | {__LINE__, |
| 15218 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15219 | AUTH_ASYNC, |
| 15220 | OK, |
| 15221 | kSecureServer, |
| 15222 | AUTH_SYNC, |
| 15223 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15224 | 3, |
| 15225 | 1, |
| 15226 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15227 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15228 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15229 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15230 | {__LINE__, |
| 15231 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15232 | AUTH_SYNC, |
| 15233 | OK, |
| 15234 | kSecureServer, |
| 15235 | AUTH_ASYNC, |
| 15236 | OK, |
| 15237 | 3, |
| 15238 | 1, |
| 15239 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15240 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15241 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15242 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15243 | {__LINE__, |
| 15244 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15245 | AUTH_SYNC, |
| 15246 | OK, |
| 15247 | kSecureServer, |
| 15248 | AUTH_ASYNC, |
| 15249 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15250 | 3, |
| 15251 | 1, |
| 15252 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15253 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15254 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15255 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15256 | {__LINE__, |
| 15257 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15258 | AUTH_ASYNC, |
| 15259 | OK, |
| 15260 | kSecureServer, |
| 15261 | AUTH_ASYNC, |
| 15262 | OK, |
| 15263 | 3, |
| 15264 | 1, |
| 15265 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15266 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15267 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15268 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15269 | {__LINE__, |
| 15270 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15271 | AUTH_ASYNC, |
| 15272 | OK, |
| 15273 | kSecureServer, |
| 15274 | AUTH_ASYNC, |
| 15275 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15276 | 3, |
| 15277 | 1, |
| 15278 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15279 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15280 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15281 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15282 | {__LINE__, |
| 15283 | kProxy, |
| 15284 | AUTH_ASYNC, |
| 15285 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15286 | kSecureServer, |
| 15287 | AUTH_ASYNC, |
| 15288 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15289 | 4, |
| 15290 | 2, |
| 15291 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15292 | TestRound(kConnect, kProxyChallenge, OK), |
| 15293 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15294 | &kServerChallenge), |
| 15295 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15296 | }; |
| 15297 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15298 | for (const auto& test_config : test_configs) { |
| 15299 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 15300 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15301 | HttpAuthHandlerMock::Factory* auth_factory( |
| 15302 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15303 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 15304 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 15305 | |
| 15306 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15307 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15308 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15309 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 15310 | std::string auth_challenge = "Mock realm=proxy"; |
| 15311 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 15312 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 15313 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15314 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15315 | empty_ssl_info, origin, |
| 15316 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15317 | auth_handler->SetGenerateExpectation( |
| 15318 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15319 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15320 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 15321 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15322 | } |
| 15323 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 15324 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15325 | std::string auth_challenge = "Mock realm=server"; |
| 15326 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 15327 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 15328 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15329 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15330 | empty_ssl_info, origin, |
| 15331 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15332 | auth_handler->SetGenerateExpectation( |
| 15333 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15334 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15335 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15336 | |
| 15337 | // The second handler always succeeds. It should only be used where there |
| 15338 | // are multiple auth sessions for server auth in the same network |
| 15339 | // transaction using the same auth scheme. |
| 15340 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15341 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15342 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 15343 | empty_ssl_info, origin, |
| 15344 | NetLogWithSource()); |
| 15345 | second_handler->SetGenerateExpectation(true, OK); |
| 15346 | auth_factory->AddMockHandler(second_handler.release(), |
| 15347 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15348 | } |
| 15349 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15350 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15351 | ConfiguredProxyResolutionService::CreateFixed( |
| 15352 | test_config.proxy_url, TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15353 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15354 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15355 | ConfiguredProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15356 | } |
| 15357 | |
| 15358 | HttpRequestInfo request; |
| 15359 | request.method = "GET"; |
| 15360 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15361 | request.traffic_annotation = |
| 15362 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15363 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15364 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15365 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15366 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 15367 | |
| 15368 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 15369 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15370 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 15371 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15372 | const TestRound& read_write_round = test_config.rounds[round]; |
| 15373 | |
| 15374 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15375 | mock_reads.back().push_back(read_write_round.read); |
| 15376 | mock_writes.back().push_back(read_write_round.write); |
| 15377 | |
| 15378 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 15379 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15380 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15381 | mock_reads.push_back(std::vector<MockRead>()); |
| 15382 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15383 | } |
| 15384 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15385 | if (read_write_round.extra_read) { |
| 15386 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15387 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15388 | if (read_write_round.extra_write) { |
| 15389 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 15390 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15391 | |
| 15392 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15393 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15394 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15395 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15396 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15397 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15398 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15399 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15400 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15401 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15402 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 15403 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15404 | } |
| 15405 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 15406 | // Transaction must be created after DataProviders, so it's destroyed before |
| 15407 | // they are as well. |
| 15408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15409 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15410 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 15411 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15412 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15413 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15414 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15415 | int rv; |
| 15416 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15417 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15418 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15419 | rv = trans.RestartWithAuth( |
| 15420 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15421 | } |
| 15422 | if (rv == ERR_IO_PENDING) |
| 15423 | rv = callback.WaitForResult(); |
| 15424 | |
| 15425 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15426 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15427 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 15428 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15429 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 15430 | continue; |
| 15431 | } |
| 15432 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15433 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15434 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15435 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15436 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15437 | } |
| 15438 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 15439 | } |
| 15440 | } |
| 15441 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15442 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15443 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15444 | HttpAuthHandlerMock::Factory* auth_factory( |
| 15445 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15446 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15447 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15448 | ConfiguredProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15449 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15450 | |
| 15451 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 15452 | auth_handler->set_connection_based(true); |
| 15453 | std::string auth_challenge = "Mock realm=server"; |
| 15454 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 15455 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 15456 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 15457 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15458 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15459 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15460 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15461 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15462 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15463 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15464 | HttpRequestInfo request; |
| 15465 | request.method = "GET"; |
| 15466 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15467 | request.traffic_annotation = |
| 15468 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15469 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15471 | |
| 15472 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 15473 | // to validate that the TCP socket is not released to the pool between |
| 15474 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15475 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 15476 | CommonConnectJobParams common_connect_job_params( |
| 15477 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 15478 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 15479 | 50, // Max sockets for pool |
| 15480 | 1, // Max sockets per group |
| 15481 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 15482 | ProxyServer::Direct(), false, // is_for_websockets |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 15483 | &common_connect_job_params); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15484 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 15485 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 15486 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15487 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15488 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15489 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15490 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15491 | |
| 15492 | const MockWrite kGet( |
| 15493 | "GET / HTTP/1.1\r\n" |
| 15494 | "Host: www.example.com\r\n" |
| 15495 | "Connection: keep-alive\r\n\r\n"); |
| 15496 | const MockWrite kGetAuth( |
| 15497 | "GET / HTTP/1.1\r\n" |
| 15498 | "Host: www.example.com\r\n" |
| 15499 | "Connection: keep-alive\r\n" |
| 15500 | "Authorization: auth_token\r\n\r\n"); |
| 15501 | |
| 15502 | const MockRead kServerChallenge( |
| 15503 | "HTTP/1.1 401 Unauthorized\r\n" |
| 15504 | "WWW-Authenticate: Mock realm=server\r\n" |
| 15505 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15506 | "Content-Length: 14\r\n\r\n" |
| 15507 | "Unauthorized\r\n"); |
| 15508 | const MockRead kSuccess( |
| 15509 | "HTTP/1.1 200 OK\r\n" |
| 15510 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15511 | "Content-Length: 3\r\n\r\n" |
| 15512 | "Yes"); |
| 15513 | |
| 15514 | MockWrite writes[] = { |
| 15515 | // First round |
| 15516 | kGet, |
| 15517 | // Second round |
| 15518 | kGetAuth, |
| 15519 | // Third round |
| 15520 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15521 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15522 | kGetAuth, |
| 15523 | // Competing request |
| 15524 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15525 | }; |
| 15526 | MockRead reads[] = { |
| 15527 | // First round |
| 15528 | kServerChallenge, |
| 15529 | // Second round |
| 15530 | kServerChallenge, |
| 15531 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15532 | kServerChallenge, |
| 15533 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15534 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15535 | // Competing response |
| 15536 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15537 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15538 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15539 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15540 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 15541 | const ClientSocketPool::GroupId kSocketGroup( |
| 15542 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 15543 | PrivacyMode::PRIVACY_MODE_DISABLED, NetworkIsolationKey(), |
| 15544 | false /* disable_secure_dns */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15545 | |
| 15546 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15547 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15548 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15549 | if (rv == ERR_IO_PENDING) |
| 15550 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15551 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15552 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15553 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15554 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15555 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15556 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 15557 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15558 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15559 | // In between rounds, another request comes in for the same domain. |
| 15560 | // It should not be able to grab the TCP socket that trans has already |
| 15561 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15562 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15563 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15564 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 15565 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15567 | // callback_compete.WaitForResult at this point would stall forever, |
| 15568 | // since the HttpNetworkTransaction does not release the request back to |
| 15569 | // the pool until after authentication completes. |
| 15570 | |
| 15571 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15572 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15573 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15574 | if (rv == ERR_IO_PENDING) |
| 15575 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15576 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15577 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15578 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15579 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15580 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15581 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 15582 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15583 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15584 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15585 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15586 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15587 | if (rv == ERR_IO_PENDING) |
| 15588 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15589 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15590 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15591 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15592 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15593 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15594 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 15595 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15596 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15597 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15598 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15599 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15600 | if (rv == ERR_IO_PENDING) |
| 15601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15602 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15603 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15604 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15605 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15606 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15607 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15608 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 15609 | // auth handler should transition to a DONE state in concert with the remote |
| 15610 | // server. But that's not something we can test here with a mock handler. |
| 15611 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 15612 | auth_handler->state()); |
| 15613 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15614 | // Read the body since the fourth round was successful. This will also |
| 15615 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 15616 | scoped_refptr<IOBufferWithSize> io_buf = |
| 15617 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15618 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15619 | if (rv == ERR_IO_PENDING) |
| 15620 | rv = callback.WaitForResult(); |
| 15621 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15622 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15623 | EXPECT_EQ(0, rv); |
| 15624 | // There are still 0 idle sockets, since the trans_compete transaction |
| 15625 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15626 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15627 | |
| 15628 | // The competing request can now finish. Wait for the headers and then |
| 15629 | // read the body. |
| 15630 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15631 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15632 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15633 | if (rv == ERR_IO_PENDING) |
| 15634 | rv = callback.WaitForResult(); |
| 15635 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15636 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15637 | EXPECT_EQ(0, rv); |
| 15638 | |
| 15639 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15640 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15641 | } |
| 15642 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15643 | // This tests the case that a request is issued via http instead of spdy after |
| 15644 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15645 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15646 | HttpRequestInfo request; |
| 15647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15648 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15649 | request.traffic_annotation = |
| 15650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15651 | |
| 15652 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15653 | MockWrite( |
| 15654 | "GET / HTTP/1.1\r\n" |
| 15655 | "Host: www.example.org\r\n" |
| 15656 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15657 | }; |
| 15658 | |
| 15659 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 15660 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 15661 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 15662 | MockRead("\r\n"), |
| 15663 | MockRead("hello world"), |
| 15664 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15665 | }; |
| 15666 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15667 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15668 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15669 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15670 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15671 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15672 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15673 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15675 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15680 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15681 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15682 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15683 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15685 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15686 | ASSERT_TRUE(response); |
| 15687 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15688 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15689 | |
| 15690 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15691 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15692 | EXPECT_EQ("hello world", response_data); |
| 15693 | |
| 15694 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15695 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15696 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15697 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 15698 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 15699 | // immediate server closing of the socket. |
| 15700 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15701 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15702 | HttpRequestInfo request; |
| 15703 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15704 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15705 | request.traffic_annotation = |
| 15706 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15707 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15708 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15709 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15711 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15712 | spdy::SpdySerializedFrame req( |
| 15713 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15714 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15715 | |
| 15716 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15717 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15718 | }; |
| 15719 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15720 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15721 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15723 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15724 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15726 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15727 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15728 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15730 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15731 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 15732 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15733 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 15734 | // it gets it. This is needed since the auth handler may get destroyed |
| 15735 | // before we get a chance to query it. |
| 15736 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 15737 | public: |
| 15738 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 15739 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15740 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15741 | |
| 15742 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15743 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 15744 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 15745 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15746 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15747 | *url_ = request->url; |
| 15748 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 15749 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15750 | } |
| 15751 | |
| 15752 | private: |
| 15753 | GURL* url_; |
| 15754 | }; |
| 15755 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15756 | // Test that if we cancel the transaction as the connection is completing, that |
| 15757 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15758 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15759 | // Setup everything about the connection to complete synchronously, so that |
| 15760 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 15761 | // for is the callback from the HttpStreamRequest. |
| 15762 | // Then cancel the transaction. |
| 15763 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 15764 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15765 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15766 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 15767 | MockRead(SYNCHRONOUS, "hello world"), |
| 15768 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15769 | }; |
| 15770 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15771 | HttpRequestInfo request; |
| 15772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15773 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15774 | request.traffic_annotation = |
| 15775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15778 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15779 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15780 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15781 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15782 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15783 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15785 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15786 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 15787 | RecordingBoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15788 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15790 | trans.reset(); // Cancel the transaction here. |
| 15791 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15792 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 15793 | } |
| 15794 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15795 | // Test that if a transaction is cancelled after receiving the headers, the |
| 15796 | // stream is drained properly and added back to the socket pool. The main |
| 15797 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 15798 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 15799 | // deleted. |
| 15800 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15801 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15802 | MockRead data_reads[] = { |
| 15803 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 15804 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 15805 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 15806 | MockRead(ASYNC, "1"), |
| 15807 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 15808 | // HttpNetworkTransaction has been deleted. |
| 15809 | MockRead(ASYNC, "2"), |
| 15810 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 15811 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15812 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15816 | |
| 15817 | { |
| 15818 | HttpRequestInfo request; |
| 15819 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15820 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15821 | request.traffic_annotation = |
| 15822 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15823 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15825 | TestCompletionCallback callback; |
| 15826 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15827 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15829 | callback.WaitForResult(); |
| 15830 | |
| 15831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15832 | ASSERT_TRUE(response); |
| 15833 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15834 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15835 | |
| 15836 | // The transaction and HttpRequestInfo are deleted. |
| 15837 | } |
| 15838 | |
| 15839 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15840 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15841 | |
| 15842 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15843 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15844 | } |
| 15845 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15846 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15847 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15848 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15849 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15850 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 15851 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15852 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15854 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15855 | HttpRequestInfo request; |
| 15856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15857 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15858 | request.traffic_annotation = |
| 15859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15860 | |
| 15861 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15862 | MockWrite( |
| 15863 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 15864 | "Host: www.example.org\r\n" |
| 15865 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15866 | }; |
| 15867 | |
| 15868 | MockRead data_reads1[] = { |
| 15869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15870 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15871 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15872 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15873 | }; |
| 15874 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15875 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15876 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15878 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15881 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15882 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15883 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 15884 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15886 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15888 | |
| 15889 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15890 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15892 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15893 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15894 | |
| 15895 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15896 | EXPECT_EQ(200, response->headers->response_code()); |
| 15897 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15898 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15899 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15900 | HostPortPair::FromString("myproxy:70")), |
| 15901 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15902 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 15903 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 15904 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15905 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15906 | |
| 15907 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15908 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15909 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15910 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15911 | } |
| 15912 | |
| 15913 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15914 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15915 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15916 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15917 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 15918 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15919 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15921 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15922 | HttpRequestInfo request; |
| 15923 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15924 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15925 | request.traffic_annotation = |
| 15926 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15927 | |
| 15928 | // Since we have proxy, should try to establish tunnel. |
| 15929 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15930 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15931 | "Host: www.example.org:443\r\n" |
| 15932 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15933 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15934 | MockWrite("GET / HTTP/1.1\r\n" |
| 15935 | "Host: www.example.org\r\n" |
| 15936 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15937 | }; |
| 15938 | |
| 15939 | MockRead data_reads1[] = { |
| 15940 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15941 | |
| 15942 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15943 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15944 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15946 | }; |
| 15947 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15948 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15949 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15950 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15953 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15955 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15956 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15957 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15958 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 15959 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15961 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15963 | |
| 15964 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15965 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15966 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15967 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15968 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15969 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15970 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15971 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15972 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15973 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15975 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15976 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15977 | |
| 15978 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15979 | EXPECT_EQ(200, response->headers->response_code()); |
| 15980 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15981 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15982 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15983 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15984 | HostPortPair::FromString("myproxy:70")), |
| 15985 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15986 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 15987 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 15988 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15989 | |
| 15990 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15991 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15992 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15993 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15994 | } |
| 15995 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15996 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 15997 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15998 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15999 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16000 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16001 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16002 | RecordingBoundTestNetLog log; |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16003 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16004 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16005 | |
| 16006 | HttpRequestInfo request; |
| 16007 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 16008 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16009 | request.traffic_annotation = |
| 16010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16011 | |
| 16012 | // Since we have proxy, should try to establish tunnel. |
| 16013 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 16014 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 16015 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16016 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 16017 | |
| 16018 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 16019 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16020 | "Connection: keep-alive\r\n\r\n"), |
| 16021 | }; |
| 16022 | |
| 16023 | MockRead data_reads1[] = { |
| 16024 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16025 | |
| 16026 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16027 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16028 | MockRead("Content-Length: 100\r\n\r\n"), |
| 16029 | MockRead(SYNCHRONOUS, OK), |
| 16030 | }; |
| 16031 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16032 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16033 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16034 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16036 | |
| 16037 | TestCompletionCallback callback1; |
| 16038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16039 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16040 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16041 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16043 | |
| 16044 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16045 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16046 | auto entries = log.GetEntries(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16047 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16048 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 16049 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16050 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16051 | entries, pos, |
| 16052 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 16053 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16054 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16055 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16056 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16057 | |
| 16058 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 16059 | EXPECT_EQ(200, response->headers->response_code()); |
| 16060 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 16061 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 16062 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 16063 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 16064 | HostPortPair::FromString("myproxy:70")), |
| 16065 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16066 | |
| 16067 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16068 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16069 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 16070 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16071 | } |
| 16072 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16073 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 16074 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16075 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16076 | session_deps_.proxy_resolution_service = |
| 16077 | ConfiguredProxyResolutionService::CreateFixed( |
| 16078 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16079 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16080 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16082 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16083 | HttpRequestInfo request; |
| 16084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16085 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16086 | request.traffic_annotation = |
| 16087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16088 | |
| 16089 | // Since we have proxy, should try to establish tunnel. |
| 16090 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16091 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16092 | "Host: www.example.org:443\r\n" |
| 16093 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16094 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16095 | MockWrite("GET / HTTP/1.1\r\n" |
| 16096 | "Host: www.example.org\r\n" |
| 16097 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16098 | }; |
| 16099 | |
| 16100 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16101 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16102 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16103 | }; |
| 16104 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16105 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16106 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16107 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16108 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16110 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16112 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 16113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16114 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16116 | |
| 16117 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16118 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16119 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16120 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16121 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 16122 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16123 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 16124 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16125 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 16126 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16127 | } |
| 16128 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16129 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16130 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16131 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16132 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16133 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16134 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16135 | spdy::SpdySerializedFrame resp( |
| 16136 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16137 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16138 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16139 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16140 | }; |
| 16141 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16142 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16143 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16144 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16145 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16146 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16148 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16150 | |
| 16151 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16152 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 16153 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16154 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 16155 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 16156 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 16157 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 16158 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16159 | |
| 16160 | HttpRequestInfo request; |
| 16161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16162 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16163 | request.traffic_annotation = |
| 16164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16166 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16167 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16168 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16169 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16171 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16172 | } |
| 16173 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16174 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16175 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16176 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16177 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16178 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16179 | request_info.url = GURL("https://www.example.com/"); |
| 16180 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16181 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16182 | request_info.traffic_annotation = |
| 16183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16184 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16185 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16186 | MockWrite data_writes[] = { |
| 16187 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16188 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16189 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16190 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16191 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16194 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16196 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16197 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16198 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16199 | rv = callback.WaitForResult(); |
| 16200 | ASSERT_EQ(error, rv); |
| 16201 | } |
| 16202 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16203 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16204 | // Just check a grab bag of cert errors. |
| 16205 | static const int kErrors[] = { |
| 16206 | ERR_CERT_COMMON_NAME_INVALID, |
| 16207 | ERR_CERT_AUTHORITY_INVALID, |
| 16208 | ERR_CERT_DATE_INVALID, |
| 16209 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 16210 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16211 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 16212 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16213 | } |
| 16214 | } |
| 16215 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16216 | // Ensure that a client certificate is removed from the SSL client auth |
| 16217 | // cache when: |
| 16218 | // 1) No proxy is involved. |
| 16219 | // 2) TLS False Start is disabled. |
| 16220 | // 3) The initial TLS handshake requests a client certificate. |
| 16221 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16222 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16223 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16224 | request_info.url = GURL("https://www.example.com/"); |
| 16225 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16226 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16227 | request_info.traffic_annotation = |
| 16228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16229 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 16230 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 16231 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16232 | |
| 16233 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 16234 | // CertificateRequest is received for the first time, the handshake will |
| 16235 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16236 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16237 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16239 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16240 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16241 | |
| 16242 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 16243 | // False Start is not being used, the result of the SSL handshake will be |
| 16244 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 16245 | // matches the result of a server sending a handshake_failure alert, |
| 16246 | // rather than a Finished message, because it requires a client |
| 16247 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16248 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16249 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16251 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16252 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16253 | |
| 16254 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 16255 | // connection to a server fails during an SSL handshake, |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16256 | // HttpNetworkTransaction will attempt to fallback with legacy cryptography |
| 16257 | // enabled on some errors. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16258 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 16259 | // requiring a client certificate, this fallback handshake should also |
| 16260 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16261 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16262 | ssl_data3.expected_disable_legacy_crypto = false; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16263 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16265 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16266 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16267 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16270 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16271 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16272 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16273 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16274 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16275 | |
| 16276 | // Complete the SSL handshake, which should abort due to requiring a |
| 16277 | // client certificate. |
| 16278 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16279 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16280 | |
| 16281 | // Indicate that no certificate should be supplied. From the perspective |
| 16282 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 16283 | // certificate, so this is the same as supply a |
| 16284 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16285 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16286 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16287 | |
| 16288 | // Ensure the certificate was added to the client auth cache before |
| 16289 | // allowing the connection to continue restarting. |
| 16290 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16291 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16292 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16293 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16294 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16295 | |
| 16296 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16297 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 16298 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16300 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16301 | |
| 16302 | // Ensure that the client certificate is removed from the cache on a |
| 16303 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16304 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16305 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16306 | } |
| 16307 | |
| 16308 | // Ensure that a client certificate is removed from the SSL client auth |
| 16309 | // cache when: |
| 16310 | // 1) No proxy is involved. |
| 16311 | // 2) TLS False Start is enabled. |
| 16312 | // 3) The initial TLS handshake requests a client certificate. |
| 16313 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16314 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16315 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16316 | request_info.url = GURL("https://www.example.com/"); |
| 16317 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16318 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16319 | request_info.traffic_annotation = |
| 16320 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16321 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 16322 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 16323 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16324 | |
| 16325 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 16326 | // return successfully after reading up to the peer's Certificate message. |
| 16327 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 16328 | // enqueue application data to be sent in the same packet as the |
| 16329 | // ChangeCipherSpec and Finished messages. |
| 16330 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 16331 | // called, which expects to process the peer's ChangeCipherSpec and |
| 16332 | // Finished messages. If there was an error negotiating with the peer, |
| 16333 | // such as due to the peer requiring a client certificate when none was |
| 16334 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 16335 | // called. |
| 16336 | |
| 16337 | // Like the non-False Start case, when a client certificate is requested by |
| 16338 | // the peer, the handshake is aborted during the Connect() call. |
| 16339 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16340 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16341 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16342 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16343 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16344 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16345 | |
| 16346 | // When a client certificate is supplied, Connect() will not be aborted |
| 16347 | // when the peer requests the certificate. Instead, the handshake will |
| 16348 | // artificially succeed, allowing the caller to write the HTTP request to |
| 16349 | // the socket. The handshake messages are not processed until Read() is |
| 16350 | // called, which then detects that the handshake was aborted, due to the |
| 16351 | // peer sending a handshake_failure because it requires a client |
| 16352 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16353 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16354 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16355 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16356 | MockRead data2_reads[] = { |
| 16357 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16358 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16359 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16360 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16361 | |
| 16362 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16363 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 16364 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16365 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16366 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16368 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16369 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16370 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16371 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 16372 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16373 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16374 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16376 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16377 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16378 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 16379 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16380 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 16381 | ssl_data5.cert_request_info = cert_request.get(); |
| 16382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16383 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 16384 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 16385 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16386 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16387 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16388 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16389 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16390 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16391 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16392 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16393 | |
| 16394 | // Complete the SSL handshake, which should abort due to requiring a |
| 16395 | // client certificate. |
| 16396 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16397 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16398 | |
| 16399 | // Indicate that no certificate should be supplied. From the perspective |
| 16400 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 16401 | // certificate, so this is the same as supply a |
| 16402 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16403 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16404 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16405 | |
| 16406 | // Ensure the certificate was added to the client auth cache before |
| 16407 | // allowing the connection to continue restarting. |
| 16408 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16409 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16410 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16411 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16412 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16413 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16414 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16415 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 16416 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16417 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16418 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16419 | |
| 16420 | // Ensure that the client certificate is removed from the cache on a |
| 16421 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16422 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16423 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16424 | } |
| 16425 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16426 | // Ensure that a client certificate is removed from the SSL client auth |
| 16427 | // cache when: |
| 16428 | // 1) An HTTPS proxy is involved. |
| 16429 | // 3) The HTTPS proxy requests a client certificate. |
| 16430 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 16431 | // proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16432 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16433 | session_deps_.proxy_resolution_service = |
| 16434 | ConfiguredProxyResolutionService::CreateFixed( |
| 16435 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16436 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16437 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16438 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16439 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 16440 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16441 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16442 | // Repeat the test for connecting to an HTTPS endpoint, then for connecting to |
| 16443 | // an HTTP endpoint. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16444 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16445 | requests[0].url = GURL("https://www.example.com/"); |
| 16446 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16447 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16448 | requests[0].traffic_annotation = |
| 16449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16450 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16451 | // HTTPS requests are tunneled. |
| 16452 | MockWrite https_writes[] = { |
| 16453 | MockWrite("CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 16454 | "Host: www.example.com:443\r\n" |
| 16455 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 16456 | }; |
| 16457 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16458 | requests[1].url = GURL("http://www.example.com/"); |
| 16459 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16460 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16461 | requests[1].traffic_annotation = |
| 16462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16463 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16464 | // HTTP requests are not. |
| 16465 | MockWrite http_writes[] = { |
| 16466 | MockWrite("GET http://www.example.com/ HTTP/1.1\r\n" |
| 16467 | "Host: www.example.com\r\n" |
| 16468 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 16469 | }; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16470 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16471 | // When the server rejects the client certificate, it will close the |
| 16472 | // connection. In TLS 1.2, this is signaled out of Connect(). In TLS 1.3 (or |
| 16473 | // TLS 1.2 with False Start), the error is returned out of the first Read(). |
| 16474 | for (bool reject_in_connect : {true, false}) { |
| 16475 | SCOPED_TRACE(reject_in_connect); |
| 16476 | // Client certificate errors are typically signaled with |
| 16477 | // ERR_BAD_SSL_CLIENT_AUTH_CERT, but sometimes the server gives an arbitrary |
| 16478 | // protocol error. |
| 16479 | for (Error reject_error : |
| 16480 | {ERR_SSL_PROTOCOL_ERROR, ERR_BAD_SSL_CLIENT_AUTH_CERT}) { |
| 16481 | SCOPED_TRACE(reject_error); |
| 16482 | // Tunneled and non-tunneled requests are handled differently. Test both. |
| 16483 | for (const HttpRequestInfo& request : requests) { |
| 16484 | SCOPED_TRACE(request.url); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16485 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16486 | session_deps_.socket_factory = |
| 16487 | std::make_unique<MockClientSocketFactory>(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16488 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16489 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16490 | // [ssl_]data[1-3]. |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16491 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 16492 | ssl_data1.cert_request_info = cert_request.get(); |
| 16493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 16494 | StaticSocketDataProvider data1; |
| 16495 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16496 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16497 | base::Optional<SSLSocketDataProvider> ssl_data2; |
| 16498 | base::Optional<StaticSocketDataProvider> data2; |
| 16499 | MockRead error_in_read[] = {MockRead(ASYNC, reject_error)}; |
| 16500 | if (reject_in_connect) { |
| 16501 | ssl_data2.emplace(ASYNC, reject_error); |
| 16502 | // There are no reads or writes. |
| 16503 | data2.emplace(); |
| 16504 | } else { |
| 16505 | ssl_data2.emplace(ASYNC, OK); |
| 16506 | // We will get one Write() in before observing the error in Read(). |
| 16507 | if (request.url.SchemeIsCryptographic()) { |
| 16508 | data2.emplace(error_in_read, https_writes); |
| 16509 | } else { |
| 16510 | data2.emplace(error_in_read, http_writes); |
| 16511 | } |
| 16512 | } |
| 16513 | ssl_data2->cert_request_info = cert_request.get(); |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16514 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 16515 | &ssl_data2.value()); |
| 16516 | session_deps_.socket_factory->AddSocketDataProvider(&data2.value()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16517 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16518 | // If the handshake returns ERR_SSL_PROTOCOL_ERROR, we attempt to |
| 16519 | // connect twice. |
| 16520 | base::Optional<SSLSocketDataProvider> ssl_data3; |
| 16521 | base::Optional<StaticSocketDataProvider> data3; |
| 16522 | if (reject_in_connect && reject_error == ERR_SSL_PROTOCOL_ERROR) { |
| 16523 | ssl_data3.emplace(ASYNC, reject_error); |
| 16524 | data3.emplace(); // There are no reads or writes. |
| 16525 | ssl_data3->cert_request_info = cert_request.get(); |
| 16526 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 16527 | &ssl_data3.value()); |
| 16528 | session_deps_.socket_factory->AddSocketDataProvider(&data3.value()); |
| 16529 | } |
| 16530 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16531 | std::unique_ptr<HttpNetworkSession> session = |
| 16532 | CreateSession(&session_deps_); |
| 16533 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16534 | |
| 16535 | // Begin the SSL handshake with the proxy. |
| 16536 | TestCompletionCallback callback; |
| 16537 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16538 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16539 | |
| 16540 | // Complete the SSL handshake, which should abort due to requiring a |
| 16541 | // client certificate. |
| 16542 | rv = callback.WaitForResult(); |
| 16543 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 16544 | |
| 16545 | // Indicate that no certificate should be supplied. From the |
| 16546 | // perspective of SSLClientCertCache, NULL is just as meaningful as a |
| 16547 | // real certificate, so this is the same as supply a |
| 16548 | // legitimate-but-unacceptable certificate. |
| 16549 | rv = |
| 16550 | trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
| 16551 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16552 | |
| 16553 | // Ensure the certificate was added to the client auth cache before |
| 16554 | // allowing the connection to continue restarting. |
| 16555 | scoped_refptr<X509Certificate> client_cert; |
| 16556 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16557 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16558 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 16559 | ASSERT_FALSE(client_cert); |
| 16560 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 16561 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16562 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16563 | HostPortPair("www.example.com", 443), &client_cert, |
| 16564 | &client_private_key)); |
| 16565 | |
| 16566 | // Restart the handshake. This will consume ssl_data2. The result code |
| 16567 | // is checked against what ssl_data2 should return. |
| 16568 | rv = callback.WaitForResult(); |
| 16569 | ASSERT_THAT(rv, AnyOf(IsError(ERR_PROXY_CONNECTION_FAILED), |
| 16570 | IsError(reject_error))); |
| 16571 | |
| 16572 | // Now that the new handshake has failed, ensure that the client |
| 16573 | // certificate was removed from the client auth cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16574 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16575 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16576 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16577 | HostPortPair("www.example.com", 443), &client_cert, |
| 16578 | &client_private_key)); |
| 16579 | } |
| 16580 | } |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16581 | } |
| 16582 | } |
| 16583 | |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 16584 | // Test that HttpNetworkTransaction correctly handles (mocked) certificate |
| 16585 | // requests during a TLS renegotiation. |
| 16586 | TEST_F(HttpNetworkTransactionTest, CertificateRequestInRenego) { |
| 16587 | HttpRequestInfo request_info; |
| 16588 | request_info.url = GURL("https://www.example.com/"); |
| 16589 | request_info.method = "GET"; |
| 16590 | request_info.load_flags = LOAD_NORMAL; |
| 16591 | request_info.traffic_annotation = |
| 16592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16593 | |
| 16594 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 16595 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
| 16596 | |
| 16597 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 16598 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 16599 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 16600 | ASSERT_TRUE(identity); |
| 16601 | |
| 16602 | // The first connection's handshake succeeds, but we get |
| 16603 | // ERR_SSL_CLIENT_AUTH_CERT_NEEDED instead of an HTTP response. |
| 16604 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 16605 | ssl_data1.cert_request_info = cert_request.get(); |
| 16606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 16607 | MockWrite data1_writes[] = { |
| 16608 | MockWrite("GET / HTTP/1.1\r\n" |
| 16609 | "Host: www.example.com\r\n" |
| 16610 | "Connection: keep-alive\r\n\r\n"), |
| 16611 | }; |
| 16612 | MockRead data1_reads[] = { |
| 16613 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED), |
| 16614 | }; |
| 16615 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 16616 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16617 | |
| 16618 | // After supplying with certificate, we restart the request from the top, |
| 16619 | // which succeeds this time. |
| 16620 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 16621 | ssl_data2.expected_send_client_cert = true; |
| 16622 | ssl_data2.expected_client_cert = identity->certificate(); |
| 16623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 16624 | MockWrite data2_writes[] = { |
| 16625 | MockWrite("GET / HTTP/1.1\r\n" |
| 16626 | "Host: www.example.com\r\n" |
| 16627 | "Connection: keep-alive\r\n\r\n"), |
| 16628 | }; |
| 16629 | MockRead data2_reads[] = { |
| 16630 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16631 | "Content-Length: 0\r\n\r\n"), |
| 16632 | }; |
| 16633 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 16634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16635 | |
| 16636 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 16637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16638 | |
| 16639 | TestCompletionCallback callback; |
| 16640 | int rv = callback.GetResult( |
| 16641 | trans.Start(&request_info, callback.callback(), NetLogWithSource())); |
| 16642 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 16643 | |
| 16644 | rv = trans.RestartWithCertificate(identity->certificate(), |
| 16645 | identity->ssl_private_key(), |
| 16646 | callback.callback()); |
| 16647 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16648 | |
| 16649 | // Ensure the certificate was added to the client auth cache |
| 16650 | // allowing the connection to continue restarting. |
| 16651 | scoped_refptr<X509Certificate> client_cert; |
| 16652 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16653 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 16654 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 16655 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 16656 | |
| 16657 | // Complete the handshake. The request now succeeds. |
| 16658 | rv = callback.WaitForResult(); |
| 16659 | ASSERT_THAT(rv, IsError(OK)); |
| 16660 | EXPECT_EQ(200, trans.GetResponseInfo()->headers->response_code()); |
| 16661 | |
| 16662 | // The client certificate remains in the cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16663 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 16664 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 16665 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 16666 | } |
| 16667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16668 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16669 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16670 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16672 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 16673 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16674 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16675 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16676 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16677 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16678 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16679 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16680 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16681 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16682 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16683 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16684 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16685 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16686 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16687 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16688 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16689 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16690 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16691 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16692 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16693 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16694 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16695 | }; |
| 16696 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16697 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16698 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16699 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16700 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16701 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 16702 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16703 | HttpRequestInfo request1; |
| 16704 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16705 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16706 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16707 | request1.traffic_annotation = |
| 16708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16709 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16710 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16711 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16713 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16714 | |
| 16715 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16716 | ASSERT_TRUE(response); |
| 16717 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16718 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16719 | |
| 16720 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16721 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16722 | EXPECT_EQ("hello!", response_data); |
| 16723 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16724 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16725 | rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 16726 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 16727 | base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16728 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16729 | |
| 16730 | HttpRequestInfo request2; |
| 16731 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16732 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16733 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16734 | request2.traffic_annotation = |
| 16735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16736 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16738 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16740 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16741 | |
| 16742 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16743 | ASSERT_TRUE(response); |
| 16744 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16745 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16746 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16747 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16748 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16749 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16750 | } |
| 16751 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16752 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16753 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16754 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16756 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 16757 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16758 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16759 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16760 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16761 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16762 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16763 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16764 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16765 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16766 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16767 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16768 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16769 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16770 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16771 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16772 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16773 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16774 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16775 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16776 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16777 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16778 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16779 | }; |
| 16780 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16781 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16782 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16783 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16784 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16785 | |
| 16786 | TestCompletionCallback callback; |
| 16787 | HttpRequestInfo request1; |
| 16788 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16789 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16790 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16791 | request1.traffic_annotation = |
| 16792 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16793 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16795 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16797 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16798 | |
| 16799 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16800 | ASSERT_TRUE(response); |
| 16801 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16802 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16803 | |
| 16804 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16805 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16806 | EXPECT_EQ("hello!", response_data); |
| 16807 | |
| 16808 | HttpRequestInfo request2; |
| 16809 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16810 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16811 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16812 | request2.traffic_annotation = |
| 16813 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16814 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16816 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16818 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16819 | |
| 16820 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16821 | ASSERT_TRUE(response); |
| 16822 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16823 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16824 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16825 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16826 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16827 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16828 | } |
| 16829 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16830 | // Regression test for https://crbug.com/546991. |
| 16831 | // The server might not be able to serve an IP pooled request, and might send a |
| 16832 | // 421 Misdirected Request response status to indicate this. |
| 16833 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 16834 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 16835 | // Two hosts resolve to the same IP address. |
| 16836 | const std::string ip_addr = "1.2.3.4"; |
| 16837 | IPAddress ip; |
| 16838 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 16839 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16840 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16841 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16842 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 16843 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 16844 | |
| 16845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16846 | |
| 16847 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16848 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16849 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 16850 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16851 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16852 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16853 | spdy::SpdySerializedFrame rst( |
| 16854 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16855 | MockWrite writes1[] = { |
| 16856 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 16857 | CreateMockWrite(rst, 6), |
| 16858 | }; |
| 16859 | |
| 16860 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16861 | spdy::SpdySerializedFrame resp1( |
| 16862 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16863 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16864 | spdy::SpdyHeaderBlock response_headers; |
| 16865 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 16866 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16867 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 16868 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 16869 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 16870 | |
| 16871 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16872 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16873 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16874 | |
| 16875 | AddSSLSocketData(); |
| 16876 | |
| 16877 | // Retry the second request on a second connection. |
| 16878 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16879 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16880 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 16881 | MockWrite writes2[] = { |
| 16882 | CreateMockWrite(req3, 0), |
| 16883 | }; |
| 16884 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16885 | spdy::SpdySerializedFrame resp3( |
| 16886 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16887 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16888 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 16889 | MockRead(ASYNC, 0, 3)}; |
| 16890 | |
| 16891 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16892 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16893 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16894 | |
| 16895 | AddSSLSocketData(); |
| 16896 | |
| 16897 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16898 | int rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 16899 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 16900 | base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16901 | EXPECT_THAT(rv, IsOk()); |
| 16902 | |
| 16903 | HttpRequestInfo request1; |
| 16904 | request1.method = "GET"; |
| 16905 | request1.url = GURL("https://www.example.org/"); |
| 16906 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16907 | request1.traffic_annotation = |
| 16908 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16909 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16910 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16911 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16912 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 16913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16914 | rv = callback.WaitForResult(); |
| 16915 | EXPECT_THAT(rv, IsOk()); |
| 16916 | |
| 16917 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 16918 | ASSERT_TRUE(response); |
| 16919 | ASSERT_TRUE(response->headers); |
| 16920 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16921 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16922 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16923 | std::string response_data; |
| 16924 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 16925 | EXPECT_EQ("hello!", response_data); |
| 16926 | |
| 16927 | HttpRequestInfo request2; |
| 16928 | request2.method = "GET"; |
| 16929 | request2.url = GURL("https://mail.example.org/"); |
| 16930 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16931 | request2.traffic_annotation = |
| 16932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16933 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16934 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16935 | RecordingBoundTestNetLog log; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16936 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 16937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16938 | rv = callback.WaitForResult(); |
| 16939 | EXPECT_THAT(rv, IsOk()); |
| 16940 | |
| 16941 | response = trans2.GetResponseInfo(); |
| 16942 | ASSERT_TRUE(response); |
| 16943 | ASSERT_TRUE(response->headers); |
| 16944 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16945 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16946 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16947 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 16948 | EXPECT_EQ("hello!", response_data); |
| 16949 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16950 | auto entries = log.GetEntries(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16951 | ExpectLogContainsSomewhere( |
| 16952 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16953 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16954 | } |
| 16955 | |
| 16956 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 16957 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 16958 | // portions of the response. |
| 16959 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 16960 | // Two hosts resolve to the same IP address. |
| 16961 | const std::string ip_addr = "1.2.3.4"; |
| 16962 | IPAddress ip; |
| 16963 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 16964 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16965 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16966 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16967 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 16968 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 16969 | |
| 16970 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16971 | |
| 16972 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16973 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16974 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 16975 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16976 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16977 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16978 | spdy::SpdySerializedFrame rst( |
| 16979 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16980 | MockWrite writes1[] = { |
| 16981 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 16982 | CreateMockWrite(rst, 6), |
| 16983 | }; |
| 16984 | |
| 16985 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16986 | spdy::SpdySerializedFrame resp1( |
| 16987 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16988 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16989 | spdy::SpdyHeaderBlock response_headers; |
| 16990 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 16991 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16992 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 16993 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 16994 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 16995 | |
| 16996 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16997 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16998 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16999 | |
| 17000 | AddSSLSocketData(); |
| 17001 | |
| 17002 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 17003 | // Retry again. |
| 17004 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17005 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17006 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 17007 | MockWrite writes2[] = { |
| 17008 | CreateMockWrite(req3, 0), |
| 17009 | }; |
| 17010 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17011 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17012 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17013 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17014 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 17015 | MockRead(ASYNC, 0, 3)}; |
| 17016 | |
| 17017 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17018 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17019 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 17020 | |
| 17021 | AddSSLSocketData(); |
| 17022 | |
| 17023 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17024 | int rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 17025 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 17026 | base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17027 | EXPECT_THAT(rv, IsOk()); |
| 17028 | |
| 17029 | HttpRequestInfo request1; |
| 17030 | request1.method = "GET"; |
| 17031 | request1.url = GURL("https://www.example.org/"); |
| 17032 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17033 | request1.traffic_annotation = |
| 17034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17035 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 17036 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17037 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17038 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 17039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17040 | rv = callback.WaitForResult(); |
| 17041 | EXPECT_THAT(rv, IsOk()); |
| 17042 | |
| 17043 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 17044 | ASSERT_TRUE(response); |
| 17045 | ASSERT_TRUE(response->headers); |
| 17046 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 17047 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 17048 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 17049 | std::string response_data; |
| 17050 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 17051 | EXPECT_EQ("hello!", response_data); |
| 17052 | |
| 17053 | HttpRequestInfo request2; |
| 17054 | request2.method = "GET"; |
| 17055 | request2.url = GURL("https://mail.example.org/"); |
| 17056 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17057 | request2.traffic_annotation = |
| 17058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17059 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 17060 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 17061 | RecordingBoundTestNetLog log; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17062 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 17063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17064 | rv = callback.WaitForResult(); |
| 17065 | EXPECT_THAT(rv, IsOk()); |
| 17066 | |
| 17067 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 17068 | // caller. |
| 17069 | response = trans2.GetResponseInfo(); |
| 17070 | ASSERT_TRUE(response); |
| 17071 | ASSERT_TRUE(response->headers); |
| 17072 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 17073 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 17074 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 17075 | EXPECT_TRUE(response->ssl_info.cert); |
| 17076 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 17077 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17078 | } |
| 17079 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17080 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 17081 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 17082 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 17083 | session_deps_.host_resolver = |
| 17084 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17086 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 17087 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17088 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17089 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17090 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17091 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17092 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 17093 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17094 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17095 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17096 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17097 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17098 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17099 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17100 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17101 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17102 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17103 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17104 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17105 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17106 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 17107 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17108 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17109 | }; |
| 17110 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 17111 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17112 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17113 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17114 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17115 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 17116 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17117 | HttpRequestInfo request1; |
| 17118 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17119 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17120 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17121 | request1.traffic_annotation = |
| 17122 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17123 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17124 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17125 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17127 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17128 | |
| 17129 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17130 | ASSERT_TRUE(response); |
| 17131 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17132 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17133 | |
| 17134 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17135 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17136 | EXPECT_EQ("hello!", response_data); |
| 17137 | |
| 17138 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17139 | rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 17140 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 17141 | base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17142 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17143 | |
| 17144 | HttpRequestInfo request2; |
| 17145 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 17146 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17147 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17148 | request2.traffic_annotation = |
| 17149 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17150 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17151 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17152 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17154 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17155 | |
| 17156 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17157 | ASSERT_TRUE(response); |
| 17158 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17159 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17160 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17161 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17162 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17163 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17164 | } |
| 17165 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17166 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17167 | const std::string https_url = "https://www.example.org:8080/"; |
| 17168 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17169 | |
| 17170 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17171 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17172 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17173 | |
| 17174 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17175 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17176 | }; |
| 17177 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17178 | spdy::SpdySerializedFrame resp1( |
| 17179 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17180 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17181 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17182 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17183 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17184 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17185 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 17186 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17187 | |
| 17188 | // HTTP GET for the HTTP URL |
| 17189 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17190 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 17191 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17192 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 17193 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17194 | }; |
| 17195 | |
| 17196 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17197 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 17198 | MockRead(ASYNC, 2, "hello"), |
| 17199 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17200 | }; |
| 17201 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17202 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17203 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17204 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17205 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17207 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 17208 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17209 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17211 | |
| 17212 | // Start the first transaction to set up the SpdySession |
| 17213 | HttpRequestInfo request1; |
| 17214 | request1.method = "GET"; |
| 17215 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17216 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17217 | request1.traffic_annotation = |
| 17218 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17219 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17220 | TestCompletionCallback callback1; |
| 17221 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17222 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 17223 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17224 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17225 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17226 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 17227 | |
| 17228 | // Now, start the HTTP request |
| 17229 | HttpRequestInfo request2; |
| 17230 | request2.method = "GET"; |
| 17231 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17232 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17233 | request2.traffic_annotation = |
| 17234 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17235 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17236 | TestCompletionCallback callback2; |
| 17237 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17238 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 17239 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17240 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17241 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17242 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 17243 | } |
| 17244 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17245 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 17246 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17247 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17248 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 17249 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17250 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17251 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17252 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17253 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17255 | |
| 17256 | // No data should be read from the alternative, because HTTP/1.1 is |
| 17257 | // negotiated. |
| 17258 | StaticSocketDataProvider data; |
| 17259 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17260 | |
| 17261 | // 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] | 17262 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17263 | // mocked. This way the request relies on the alternate Job. |
| 17264 | StaticSocketDataProvider data_refused; |
| 17265 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 17266 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 17267 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17268 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17269 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 17270 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17271 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 17272 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 17273 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 17274 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 17275 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17276 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17277 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17279 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17280 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17281 | request.traffic_annotation = |
| 17282 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17283 | TestCompletionCallback callback; |
| 17284 | |
| 17285 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17286 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17287 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17288 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17289 | } |
| 17290 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17291 | // 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] | 17292 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17293 | // succeeds, the request should succeed, even if the latter fails because |
| 17294 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17295 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17296 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 17297 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17298 | |
| 17299 | // Negotiate HTTP/1.1 with alternative. |
| 17300 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17301 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 17303 | |
| 17304 | // No data should be read from the alternative, because HTTP/1.1 is |
| 17305 | // negotiated. |
| 17306 | StaticSocketDataProvider data; |
| 17307 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17308 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17309 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17310 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17311 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 17313 | |
| 17314 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17315 | MockWrite("GET / HTTP/1.1\r\n" |
| 17316 | "Host: www.example.org\r\n" |
| 17317 | "Connection: keep-alive\r\n\r\n"), |
| 17318 | MockWrite("GET /second HTTP/1.1\r\n" |
| 17319 | "Host: www.example.org\r\n" |
| 17320 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17321 | }; |
| 17322 | |
| 17323 | MockRead http_reads[] = { |
| 17324 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17325 | MockRead("Content-Type: text/html\r\n"), |
| 17326 | MockRead("Content-Length: 6\r\n\r\n"), |
| 17327 | MockRead("foobar"), |
| 17328 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17329 | MockRead("Content-Type: text/html\r\n"), |
| 17330 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17331 | MockRead("another"), |
| 17332 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17333 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17334 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17335 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17336 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 17338 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17339 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 17340 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 17341 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 17342 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 17343 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17344 | |
| 17345 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 17346 | HttpRequestInfo request1; |
| 17347 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17348 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17349 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17350 | request1.traffic_annotation = |
| 17351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17352 | TestCompletionCallback callback1; |
| 17353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17354 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17355 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17356 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17357 | |
| 17358 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17359 | ASSERT_TRUE(response1); |
| 17360 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17361 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 17362 | |
| 17363 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17364 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17365 | EXPECT_EQ("foobar", response_data1); |
| 17366 | |
| 17367 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 17368 | // for alternative service. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 17369 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 17370 | alternative_service, NetworkIsolationKey())); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17371 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17372 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17373 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17374 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17375 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 17376 | HttpRequestInfo request2; |
| 17377 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17378 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17379 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17380 | request2.traffic_annotation = |
| 17381 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17382 | TestCompletionCallback callback2; |
| 17383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17384 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17385 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17386 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17387 | |
| 17388 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17389 | ASSERT_TRUE(response2); |
| 17390 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17391 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 17392 | |
| 17393 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17394 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17395 | EXPECT_EQ("another", response_data2); |
| 17396 | } |
| 17397 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17398 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 17399 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 17400 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17401 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17402 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17403 | HostPortPair alternative("alternative.example.org", 443); |
| 17404 | std::string origin_url = "https://origin.example.org:443"; |
| 17405 | std::string alternative_url = "https://alternative.example.org:443"; |
| 17406 | |
| 17407 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 17408 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17409 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17411 | |
| 17412 | // HTTP/1.1 data for |request1| and |request2|. |
| 17413 | MockWrite http_writes[] = { |
| 17414 | MockWrite( |
| 17415 | "GET / HTTP/1.1\r\n" |
| 17416 | "Host: alternative.example.org\r\n" |
| 17417 | "Connection: keep-alive\r\n\r\n"), |
| 17418 | MockWrite( |
| 17419 | "GET / HTTP/1.1\r\n" |
| 17420 | "Host: alternative.example.org\r\n" |
| 17421 | "Connection: keep-alive\r\n\r\n"), |
| 17422 | }; |
| 17423 | |
| 17424 | MockRead http_reads[] = { |
| 17425 | MockRead( |
| 17426 | "HTTP/1.1 200 OK\r\n" |
| 17427 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 17428 | "Content-Length: 40\r\n\r\n" |
| 17429 | "first HTTP/1.1 response from alternative"), |
| 17430 | MockRead( |
| 17431 | "HTTP/1.1 200 OK\r\n" |
| 17432 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 17433 | "Content-Length: 41\r\n\r\n" |
| 17434 | "second HTTP/1.1 response from alternative"), |
| 17435 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17436 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17437 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17438 | |
| 17439 | // This test documents that an alternate Job should not pool to an already |
| 17440 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17441 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17442 | StaticSocketDataProvider data_refused; |
| 17443 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 17444 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 17445 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17446 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 17448 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17449 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 17450 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 17451 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 17452 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 17453 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17454 | |
| 17455 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17456 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17457 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17458 | request1.method = "GET"; |
| 17459 | request1.url = GURL(alternative_url); |
| 17460 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17461 | request1.traffic_annotation = |
| 17462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17463 | TestCompletionCallback callback1; |
| 17464 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17465 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17466 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17467 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17468 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17469 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17470 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17471 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17472 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 17473 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17474 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17475 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 17476 | |
| 17477 | // Request for origin.example.org, which has an alternative service. This |
| 17478 | // will start two Jobs: the alternative looks for connections to pool to, |
| 17479 | // 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] | 17480 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17481 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17482 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17483 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17484 | request2.method = "GET"; |
| 17485 | request2.url = GURL(origin_url); |
| 17486 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17487 | request2.traffic_annotation = |
| 17488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17489 | TestCompletionCallback callback2; |
| 17490 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17491 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17492 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17493 | |
| 17494 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 17495 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17496 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17497 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17498 | request3.method = "GET"; |
| 17499 | request3.url = GURL(alternative_url); |
| 17500 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17501 | request3.traffic_annotation = |
| 17502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17503 | TestCompletionCallback callback3; |
| 17504 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17505 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17506 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17507 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17508 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17509 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17510 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17511 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17512 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 17513 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17514 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17515 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 17516 | } |
| 17517 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17518 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17519 | const std::string https_url = "https://www.example.org:8080/"; |
| 17520 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17521 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17522 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17523 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17524 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17525 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17526 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 17527 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 17528 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 17529 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17530 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17531 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17532 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 17533 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 17534 | |
| 17535 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17536 | spdy::SpdyHeaderBlock req2_block; |
| 17537 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 17538 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 17539 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 17540 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 17541 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17542 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17543 | |
| 17544 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17545 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 17546 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17547 | }; |
| 17548 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17549 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17550 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17551 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17552 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17553 | spdy::SpdySerializedFrame body1( |
| 17554 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 17555 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17556 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17557 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17558 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17559 | spdy::SpdySerializedFrame resp2( |
| 17560 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17561 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17562 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17563 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17564 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17565 | CreateMockRead(wrapped_resp1, 4), |
| 17566 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17567 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17568 | CreateMockRead(resp2, 8), |
| 17569 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17570 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 17571 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17572 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17573 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17574 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 17575 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17576 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17577 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 17578 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17579 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 17580 | RecordingTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17581 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17582 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17583 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17585 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17586 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17588 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17589 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17590 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17591 | |
| 17592 | // Start the first transaction to set up the SpdySession |
| 17593 | HttpRequestInfo request1; |
| 17594 | request1.method = "GET"; |
| 17595 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17596 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17597 | request1.traffic_annotation = |
| 17598 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17599 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17600 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17601 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17602 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17603 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 17604 | data1.RunUntilPaused(); |
| 17605 | base::RunLoop().RunUntilIdle(); |
| 17606 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17607 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17608 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 17609 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 17610 | LoadTimingInfo load_timing_info1; |
| 17611 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 17612 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 17613 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 17614 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17615 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17616 | HttpRequestInfo request2; |
| 17617 | request2.method = "GET"; |
| 17618 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17619 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17620 | request2.traffic_annotation = |
| 17621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17622 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17623 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17624 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17625 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17626 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 17627 | data1.RunUntilPaused(); |
| 17628 | base::RunLoop().RunUntilIdle(); |
| 17629 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17630 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17631 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17632 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 17633 | |
| 17634 | LoadTimingInfo load_timing_info2; |
| 17635 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 17636 | // The established SPDY sessions is considered reused by the HTTP request. |
| 17637 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 17638 | // HTTP requests over a SPDY session should have a different connection |
| 17639 | // socket_log_id than requests over a tunnel. |
| 17640 | 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] | 17641 | } |
| 17642 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17643 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 17644 | // that we do not pool other origins that resolve to the same IP when |
| 17645 | // the certificate does not match the new origin. |
| 17646 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17647 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17648 | const std::string url1 = "http://www.example.org/"; |
| 17649 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17650 | const std::string ip_addr = "1.2.3.4"; |
| 17651 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17652 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17653 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17654 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17655 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17656 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17657 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17658 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17659 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17660 | |
| 17661 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17662 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17663 | }; |
| 17664 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17665 | spdy::SpdySerializedFrame resp1( |
| 17666 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17667 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17668 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17669 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 17670 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17671 | }; |
| 17672 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17673 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 17674 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 17675 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17676 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 17677 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17678 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17679 | |
| 17680 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17681 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17682 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17683 | |
| 17684 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17685 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17686 | }; |
| 17687 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17688 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17689 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17690 | spdy::SpdySerializedFrame body2( |
| 17691 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17692 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17693 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17695 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17696 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17697 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17698 | |
| 17699 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 17700 | // all others direct. |
| 17701 | ProxyConfig proxy_config; |
| 17702 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17703 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 17704 | std::make_unique<ConfiguredProxyResolutionService>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17705 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17706 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 17707 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17708 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17709 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17710 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17711 | // Load a valid cert. Note, that this does not need to |
| 17712 | // be valid for proxy because the MockSSLClientSocket does |
| 17713 | // not actually verify it. But SpdySession will use this |
| 17714 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17715 | ssl1.ssl_info.cert = |
| 17716 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 17717 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17719 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17720 | |
| 17721 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17722 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17724 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17725 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17726 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17727 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17728 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17729 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17730 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17731 | |
| 17732 | // Start the first transaction to set up the SpdySession |
| 17733 | HttpRequestInfo request1; |
| 17734 | request1.method = "GET"; |
| 17735 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17736 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17737 | request1.traffic_annotation = |
| 17738 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17739 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17740 | TestCompletionCallback callback1; |
| 17741 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17742 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17743 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 17744 | data1.RunUntilPaused(); |
| 17745 | base::RunLoop().RunUntilIdle(); |
| 17746 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17747 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17748 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17749 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 17750 | |
| 17751 | // Now, start the HTTP request |
| 17752 | HttpRequestInfo request2; |
| 17753 | request2.method = "GET"; |
| 17754 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17755 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17756 | request2.traffic_annotation = |
| 17757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17758 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17759 | TestCompletionCallback callback2; |
| 17760 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17761 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 17762 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17763 | |
| 17764 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17765 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17766 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 17767 | } |
| 17768 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17769 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 17770 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 17771 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 17772 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17773 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17774 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17775 | |
| 17776 | MockRead reads1[] = { |
| 17777 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 17778 | }; |
| 17779 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17780 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17781 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17782 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17783 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17784 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17785 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17786 | }; |
| 17787 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17788 | spdy::SpdySerializedFrame resp2( |
| 17789 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17790 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17791 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17792 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 17793 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17794 | }; |
| 17795 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17796 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17797 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17798 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17799 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 17800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17802 | |
| 17803 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17804 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 17805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17806 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17808 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 17809 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17810 | |
| 17811 | // Start the first transaction to set up the SpdySession and verify that |
| 17812 | // connection was closed. |
| 17813 | HttpRequestInfo request1; |
| 17814 | request1.method = "GET"; |
| 17815 | request1.url = GURL(https_url); |
| 17816 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17817 | request1.traffic_annotation = |
| 17818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17819 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17820 | TestCompletionCallback callback1; |
| 17821 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17822 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17823 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17824 | |
| 17825 | // Now, start the second request and make sure it succeeds. |
| 17826 | HttpRequestInfo request2; |
| 17827 | request2.method = "GET"; |
| 17828 | request2.url = GURL(https_url); |
| 17829 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17830 | request2.traffic_annotation = |
| 17831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17832 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17833 | TestCompletionCallback callback2; |
| 17834 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17835 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17836 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17837 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17838 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 17839 | } |
| 17840 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17841 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17842 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17843 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17844 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17845 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17846 | |
| 17847 | // Use two different hosts with different IPs so they don't get pooled. |
| 17848 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 17849 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17851 | |
| 17852 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17853 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17854 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17855 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17856 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17857 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17858 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17859 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17860 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17861 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17862 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17863 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17864 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17865 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17866 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17867 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17868 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17869 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17870 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17871 | }; |
| 17872 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17873 | // Use a separate test instance for the separate SpdySession that will be |
| 17874 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17875 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17876 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 17877 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17878 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17879 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17880 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17881 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17882 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17883 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17884 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17885 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17886 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17887 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17888 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17889 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17890 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17891 | }; |
| 17892 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17893 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 17894 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17895 | |
| 17896 | MockWrite http_write[] = { |
| 17897 | MockWrite("GET / HTTP/1.1\r\n" |
| 17898 | "Host: www.a.com\r\n" |
| 17899 | "Connection: keep-alive\r\n\r\n"), |
| 17900 | }; |
| 17901 | |
| 17902 | MockRead http_read[] = { |
| 17903 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17904 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 17905 | MockRead("Content-Length: 6\r\n\r\n"), |
| 17906 | MockRead("hello!"), |
| 17907 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17908 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17909 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17910 | |
| 17911 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17912 | SpdySessionKey spdy_session_key_a( |
| 17913 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 17914 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17915 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17916 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17917 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17918 | |
| 17919 | TestCompletionCallback callback; |
| 17920 | HttpRequestInfo request1; |
| 17921 | request1.method = "GET"; |
| 17922 | request1.url = GURL("https://www.a.com/"); |
| 17923 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17924 | request1.traffic_annotation = |
| 17925 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17926 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17927 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17928 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17929 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17931 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17932 | |
| 17933 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17934 | ASSERT_TRUE(response); |
| 17935 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17936 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17937 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17938 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17939 | |
| 17940 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17941 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17942 | EXPECT_EQ("hello!", response_data); |
| 17943 | trans.reset(); |
| 17944 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17945 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17946 | |
| 17947 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17948 | SpdySessionKey spdy_session_key_b( |
| 17949 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 17950 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17951 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17952 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17953 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17954 | HttpRequestInfo request2; |
| 17955 | request2.method = "GET"; |
| 17956 | request2.url = GURL("https://www.b.com/"); |
| 17957 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17958 | request2.traffic_annotation = |
| 17959 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17960 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17961 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17962 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17963 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17965 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17966 | |
| 17967 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17968 | ASSERT_TRUE(response); |
| 17969 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17970 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17971 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17972 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17973 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17974 | EXPECT_EQ("hello!", response_data); |
| 17975 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17976 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17977 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17978 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17979 | |
| 17980 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17981 | SpdySessionKey spdy_session_key_a1( |
| 17982 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 17983 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17984 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17985 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17986 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17987 | HttpRequestInfo request3; |
| 17988 | request3.method = "GET"; |
| 17989 | request3.url = GURL("http://www.a.com/"); |
| 17990 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17991 | request3.traffic_annotation = |
| 17992 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17993 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17994 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17995 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17996 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17998 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17999 | |
| 18000 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18001 | ASSERT_TRUE(response); |
| 18002 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18003 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 18004 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 18005 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18006 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18007 | EXPECT_EQ("hello!", response_data); |
| 18008 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18009 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18010 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18011 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18012 | } |
| 18013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18014 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18015 | HttpRequestInfo request; |
| 18016 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18017 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18018 | request.traffic_annotation = |
| 18019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18020 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18022 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18023 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18024 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18025 | StaticSocketDataProvider data; |
| 18026 | data.set_connect_data(mock_connect); |
| 18027 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18028 | |
| 18029 | TestCompletionCallback callback; |
| 18030 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18031 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18032 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18033 | |
| 18034 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18035 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18036 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18037 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18038 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18039 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18040 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18041 | |
| 18042 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18043 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18044 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18045 | } |
| 18046 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18047 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18048 | HttpRequestInfo request; |
| 18049 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18050 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18051 | request.traffic_annotation = |
| 18052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18055 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18056 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18057 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18058 | StaticSocketDataProvider data; |
| 18059 | data.set_connect_data(mock_connect); |
| 18060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18061 | |
| 18062 | TestCompletionCallback callback; |
| 18063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18064 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18066 | |
| 18067 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18068 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18069 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18070 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18071 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18072 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18073 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18074 | |
| 18075 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18076 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18077 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18078 | } |
| 18079 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18080 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18081 | HttpRequestInfo request; |
| 18082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18083 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18084 | request.traffic_annotation = |
| 18085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18089 | |
| 18090 | MockWrite data_writes[] = { |
| 18091 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18092 | }; |
| 18093 | MockRead data_reads[] = { |
| 18094 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 18095 | }; |
| 18096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18097 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18098 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18099 | |
| 18100 | TestCompletionCallback callback; |
| 18101 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18102 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18104 | |
| 18105 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18106 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18107 | } |
| 18108 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18109 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18110 | HttpRequestInfo request; |
| 18111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18112 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18113 | request.traffic_annotation = |
| 18114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18115 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18117 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18118 | |
| 18119 | MockWrite data_writes[] = { |
| 18120 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 18121 | }; |
| 18122 | MockRead data_reads[] = { |
| 18123 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 18124 | }; |
| 18125 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18126 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18128 | |
| 18129 | TestCompletionCallback callback; |
| 18130 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18131 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18133 | |
| 18134 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18135 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18136 | } |
| 18137 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18138 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18139 | HttpRequestInfo request; |
| 18140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18141 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18142 | request.traffic_annotation = |
| 18143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18144 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18147 | |
| 18148 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18149 | MockWrite( |
| 18150 | "GET / HTTP/1.1\r\n" |
| 18151 | "Host: www.example.org\r\n" |
| 18152 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18153 | }; |
| 18154 | MockRead data_reads[] = { |
| 18155 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18156 | }; |
| 18157 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18158 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18160 | |
| 18161 | TestCompletionCallback callback; |
| 18162 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18163 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18164 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18165 | |
| 18166 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18167 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18168 | } |
| 18169 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18170 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18171 | HttpRequestInfo request; |
| 18172 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18173 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18174 | request.traffic_annotation = |
| 18175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18176 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18177 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18178 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18179 | |
| 18180 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18181 | MockWrite( |
| 18182 | "GET / HTTP/1.1\r\n" |
| 18183 | "Host: www.example.org\r\n" |
| 18184 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18185 | }; |
| 18186 | MockRead data_reads[] = { |
| 18187 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18188 | }; |
| 18189 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18190 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18191 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18192 | |
| 18193 | TestCompletionCallback callback; |
| 18194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18195 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18197 | |
| 18198 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18199 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18200 | } |
| 18201 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18202 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 18203 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18204 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18205 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 18206 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18207 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 18208 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18209 | |
| 18210 | // Set up SSL request. |
| 18211 | |
| 18212 | HttpRequestInfo ssl_request; |
| 18213 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18214 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18215 | ssl_request.traffic_annotation = |
| 18216 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18217 | |
| 18218 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18219 | MockWrite( |
| 18220 | "GET / HTTP/1.1\r\n" |
| 18221 | "Host: www.example.org\r\n" |
| 18222 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18223 | }; |
| 18224 | MockRead ssl_reads[] = { |
| 18225 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18226 | MockRead("Content-Length: 11\r\n\r\n"), |
| 18227 | MockRead("hello world"), |
| 18228 | MockRead(SYNCHRONOUS, OK), |
| 18229 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18230 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18231 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 18232 | |
| 18233 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18235 | |
| 18236 | // Set up HTTP request. |
| 18237 | |
| 18238 | HttpRequestInfo http_request; |
| 18239 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18240 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18241 | http_request.traffic_annotation = |
| 18242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18243 | |
| 18244 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18245 | MockWrite( |
| 18246 | "GET / HTTP/1.1\r\n" |
| 18247 | "Host: www.example.org\r\n" |
| 18248 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18249 | }; |
| 18250 | MockRead http_reads[] = { |
| 18251 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18252 | MockRead("Content-Length: 7\r\n\r\n"), |
| 18253 | MockRead("falafel"), |
| 18254 | MockRead(SYNCHRONOUS, OK), |
| 18255 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18256 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18257 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 18258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18260 | |
| 18261 | // Start the SSL request. |
| 18262 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18263 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18264 | ASSERT_EQ(ERR_IO_PENDING, |
| 18265 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 18266 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18267 | |
| 18268 | // Start the HTTP request. Pool should stall. |
| 18269 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18270 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18271 | ASSERT_EQ(ERR_IO_PENDING, |
| 18272 | http_trans.Start(&http_request, http_callback.callback(), |
| 18273 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18274 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18275 | |
| 18276 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18277 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18278 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18279 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18280 | EXPECT_EQ("hello world", response_data); |
| 18281 | |
| 18282 | // The SSL socket should automatically be closed, so the HTTP request can |
| 18283 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 18284 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18285 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18286 | |
| 18287 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18288 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18289 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18290 | EXPECT_EQ("falafel", response_data); |
| 18291 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18292 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18293 | } |
| 18294 | |
| 18295 | // Tests that when a SSL connection is established but there's no corresponding |
| 18296 | // request that needs it, the new socket is closed if the transport socket pool |
| 18297 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18298 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18299 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 18300 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18301 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 18302 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18303 | |
| 18304 | // Set up an ssl request. |
| 18305 | |
| 18306 | HttpRequestInfo ssl_request; |
| 18307 | ssl_request.method = "GET"; |
| 18308 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18309 | ssl_request.traffic_annotation = |
| 18310 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18311 | |
| 18312 | // No data will be sent on the SSL socket. |
| 18313 | StaticSocketDataProvider ssl_data; |
| 18314 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 18315 | |
| 18316 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18318 | |
| 18319 | // Set up HTTP request. |
| 18320 | |
| 18321 | HttpRequestInfo http_request; |
| 18322 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18323 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18324 | http_request.traffic_annotation = |
| 18325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18326 | |
| 18327 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18328 | MockWrite( |
| 18329 | "GET / HTTP/1.1\r\n" |
| 18330 | "Host: www.example.org\r\n" |
| 18331 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18332 | }; |
| 18333 | MockRead http_reads[] = { |
| 18334 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18335 | MockRead("Content-Length: 7\r\n\r\n"), |
| 18336 | MockRead("falafel"), |
| 18337 | MockRead(SYNCHRONOUS, OK), |
| 18338 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18339 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18340 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 18341 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18343 | |
| 18344 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 18345 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 18346 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 18347 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 18348 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18349 | |
| 18350 | // Start the HTTP request. Pool should stall. |
| 18351 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18352 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18353 | ASSERT_EQ(ERR_IO_PENDING, |
| 18354 | http_trans.Start(&http_request, http_callback.callback(), |
| 18355 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18356 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18357 | |
| 18358 | // The SSL connection will automatically be closed once the connection is |
| 18359 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18360 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18361 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18362 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18363 | EXPECT_EQ("falafel", response_data); |
| 18364 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18365 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18366 | } |
| 18367 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18368 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18369 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18370 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18371 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18372 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18373 | |
| 18374 | HttpRequestInfo request; |
| 18375 | request.method = "POST"; |
| 18376 | request.url = GURL("http://www.foo.com/"); |
| 18377 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18378 | request.traffic_annotation = |
| 18379 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18380 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18382 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18383 | // Send headers successfully, but get an error while sending the body. |
| 18384 | MockWrite data_writes[] = { |
| 18385 | MockWrite("POST / HTTP/1.1\r\n" |
| 18386 | "Host: www.foo.com\r\n" |
| 18387 | "Connection: keep-alive\r\n" |
| 18388 | "Content-Length: 3\r\n\r\n"), |
| 18389 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18390 | }; |
| 18391 | |
| 18392 | MockRead data_reads[] = { |
| 18393 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18394 | MockRead("hello world"), |
| 18395 | MockRead(SYNCHRONOUS, OK), |
| 18396 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18397 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18399 | |
| 18400 | TestCompletionCallback callback; |
| 18401 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18402 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18403 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18404 | |
| 18405 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18408 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18409 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18410 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18411 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18412 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18413 | |
| 18414 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18415 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18417 | EXPECT_EQ("hello world", response_data); |
| 18418 | } |
| 18419 | |
| 18420 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 18421 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18422 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18423 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18425 | MockWrite data_writes[] = { |
| 18426 | MockWrite("GET / HTTP/1.1\r\n" |
| 18427 | "Host: www.foo.com\r\n" |
| 18428 | "Connection: keep-alive\r\n\r\n"), |
| 18429 | MockWrite("POST / HTTP/1.1\r\n" |
| 18430 | "Host: www.foo.com\r\n" |
| 18431 | "Connection: keep-alive\r\n" |
| 18432 | "Content-Length: 3\r\n\r\n"), |
| 18433 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18434 | }; |
| 18435 | |
| 18436 | MockRead data_reads[] = { |
| 18437 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 18438 | "Content-Length: 14\r\n\r\n"), |
| 18439 | MockRead("first response"), |
| 18440 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 18441 | "Content-Length: 15\r\n\r\n"), |
| 18442 | MockRead("second response"), |
| 18443 | MockRead(SYNCHRONOUS, OK), |
| 18444 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18445 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18447 | |
| 18448 | TestCompletionCallback callback; |
| 18449 | HttpRequestInfo request1; |
| 18450 | request1.method = "GET"; |
| 18451 | request1.url = GURL("http://www.foo.com/"); |
| 18452 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18453 | request1.traffic_annotation = |
| 18454 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18455 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18456 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18457 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18458 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18460 | |
| 18461 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18462 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18463 | |
| 18464 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18465 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18466 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18467 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18468 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 18469 | |
| 18470 | std::string response_data1; |
| 18471 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18473 | EXPECT_EQ("first response", response_data1); |
| 18474 | // Delete the transaction to release the socket back into the socket pool. |
| 18475 | trans1.reset(); |
| 18476 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18477 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18478 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18479 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18480 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18481 | |
| 18482 | HttpRequestInfo request2; |
| 18483 | request2.method = "POST"; |
| 18484 | request2.url = GURL("http://www.foo.com/"); |
| 18485 | request2.upload_data_stream = &upload_data_stream; |
| 18486 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18487 | request2.traffic_annotation = |
| 18488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18490 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18491 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18493 | |
| 18494 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18497 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18498 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18499 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18500 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18501 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 18502 | |
| 18503 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18504 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18506 | EXPECT_EQ("second response", response_data2); |
| 18507 | } |
| 18508 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18509 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18510 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18511 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18512 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18513 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18514 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18515 | |
| 18516 | HttpRequestInfo request; |
| 18517 | request.method = "POST"; |
| 18518 | request.url = GURL("http://www.foo.com/"); |
| 18519 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18520 | request.traffic_annotation = |
| 18521 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18522 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18525 | // Send headers successfully, but get an error while sending the body. |
| 18526 | MockWrite data_writes[] = { |
| 18527 | MockWrite("POST / HTTP/1.1\r\n" |
| 18528 | "Host: www.foo.com\r\n" |
| 18529 | "Connection: keep-alive\r\n" |
| 18530 | "Content-Length: 3\r\n\r\n" |
| 18531 | "fo"), |
| 18532 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18533 | }; |
| 18534 | |
| 18535 | MockRead data_reads[] = { |
| 18536 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18537 | MockRead("hello world"), |
| 18538 | MockRead(SYNCHRONOUS, OK), |
| 18539 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18540 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18541 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18542 | |
| 18543 | TestCompletionCallback callback; |
| 18544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18545 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18547 | |
| 18548 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18549 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18552 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18553 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18554 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18555 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18556 | |
| 18557 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18558 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18560 | EXPECT_EQ("hello world", response_data); |
| 18561 | } |
| 18562 | |
| 18563 | // This tests the more common case than the previous test, where headers and |
| 18564 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18565 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 18566 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18567 | |
| 18568 | HttpRequestInfo request; |
| 18569 | request.method = "POST"; |
| 18570 | request.url = GURL("http://www.foo.com/"); |
| 18571 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18572 | request.traffic_annotation = |
| 18573 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18574 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18576 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18577 | // Send headers successfully, but get an error while sending the body. |
| 18578 | MockWrite data_writes[] = { |
| 18579 | MockWrite("POST / HTTP/1.1\r\n" |
| 18580 | "Host: www.foo.com\r\n" |
| 18581 | "Connection: keep-alive\r\n" |
| 18582 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18583 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18584 | }; |
| 18585 | |
| 18586 | MockRead data_reads[] = { |
| 18587 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18588 | MockRead("hello world"), |
| 18589 | MockRead(SYNCHRONOUS, OK), |
| 18590 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18591 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18592 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18593 | |
| 18594 | TestCompletionCallback callback; |
| 18595 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18596 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18598 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 18599 | // they can't be merged with the body in a single send. Not currently |
| 18600 | // necessary since a chunked body is never merged with headers, but this makes |
| 18601 | // the test more future proof. |
| 18602 | base::RunLoop().RunUntilIdle(); |
| 18603 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 18604 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18605 | |
| 18606 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18607 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18609 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18610 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18611 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18612 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18613 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18614 | |
| 18615 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18616 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18617 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18618 | EXPECT_EQ("hello world", response_data); |
| 18619 | } |
| 18620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18621 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18622 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18623 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18624 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18625 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18626 | |
| 18627 | HttpRequestInfo request; |
| 18628 | request.method = "POST"; |
| 18629 | request.url = GURL("http://www.foo.com/"); |
| 18630 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18631 | request.traffic_annotation = |
| 18632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18636 | |
| 18637 | MockWrite data_writes[] = { |
| 18638 | MockWrite("POST / HTTP/1.1\r\n" |
| 18639 | "Host: www.foo.com\r\n" |
| 18640 | "Connection: keep-alive\r\n" |
| 18641 | "Content-Length: 3\r\n\r\n"), |
| 18642 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18643 | }; |
| 18644 | |
| 18645 | MockRead data_reads[] = { |
| 18646 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 18647 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18648 | MockRead("hello world"), |
| 18649 | MockRead(SYNCHRONOUS, OK), |
| 18650 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18651 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18653 | |
| 18654 | TestCompletionCallback callback; |
| 18655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18656 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18658 | |
| 18659 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18660 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18662 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18663 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18664 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18665 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18666 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18667 | |
| 18668 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18669 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18670 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18671 | EXPECT_EQ("hello world", response_data); |
| 18672 | } |
| 18673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18674 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18675 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18676 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18677 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18678 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18679 | |
| 18680 | HttpRequestInfo request; |
| 18681 | request.method = "POST"; |
| 18682 | request.url = GURL("http://www.foo.com/"); |
| 18683 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18684 | request.traffic_annotation = |
| 18685 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18686 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18689 | // Send headers successfully, but get an error while sending the body. |
| 18690 | MockWrite data_writes[] = { |
| 18691 | MockWrite("POST / HTTP/1.1\r\n" |
| 18692 | "Host: www.foo.com\r\n" |
| 18693 | "Connection: keep-alive\r\n" |
| 18694 | "Content-Length: 3\r\n\r\n"), |
| 18695 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18696 | }; |
| 18697 | |
| 18698 | MockRead data_reads[] = { |
| 18699 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 18700 | MockRead("hello world"), |
| 18701 | MockRead(SYNCHRONOUS, OK), |
| 18702 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18703 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18704 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18705 | |
| 18706 | TestCompletionCallback callback; |
| 18707 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18708 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18710 | |
| 18711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18712 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18713 | } |
| 18714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18715 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18716 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18717 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18718 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18719 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18720 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18721 | |
| 18722 | HttpRequestInfo request; |
| 18723 | request.method = "POST"; |
| 18724 | request.url = GURL("http://www.foo.com/"); |
| 18725 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18726 | request.traffic_annotation = |
| 18727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18731 | // Send headers successfully, but get an error while sending the body. |
| 18732 | MockWrite data_writes[] = { |
| 18733 | MockWrite("POST / HTTP/1.1\r\n" |
| 18734 | "Host: www.foo.com\r\n" |
| 18735 | "Connection: keep-alive\r\n" |
| 18736 | "Content-Length: 3\r\n\r\n"), |
| 18737 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18738 | }; |
| 18739 | |
| 18740 | MockRead data_reads[] = { |
| 18741 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 18742 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 18743 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 18744 | MockRead("Content-Length: 0\r\n\r\n"), |
| 18745 | MockRead(SYNCHRONOUS, OK), |
| 18746 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18747 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18749 | |
| 18750 | TestCompletionCallback callback; |
| 18751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18752 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18754 | |
| 18755 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18756 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18757 | } |
| 18758 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18759 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18760 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18761 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18762 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18763 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18764 | |
| 18765 | HttpRequestInfo request; |
| 18766 | request.method = "POST"; |
| 18767 | request.url = GURL("http://www.foo.com/"); |
| 18768 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18769 | request.traffic_annotation = |
| 18770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18771 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18774 | // Send headers successfully, but get an error while sending the body. |
| 18775 | MockWrite data_writes[] = { |
| 18776 | MockWrite("POST / HTTP/1.1\r\n" |
| 18777 | "Host: www.foo.com\r\n" |
| 18778 | "Connection: keep-alive\r\n" |
| 18779 | "Content-Length: 3\r\n\r\n"), |
| 18780 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18781 | }; |
| 18782 | |
| 18783 | MockRead data_reads[] = { |
| 18784 | MockRead("HTTP 0.9 rocks!"), |
| 18785 | MockRead(SYNCHRONOUS, OK), |
| 18786 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18787 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18789 | |
| 18790 | TestCompletionCallback callback; |
| 18791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18794 | |
| 18795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18796 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18797 | } |
| 18798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18799 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18800 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18801 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18802 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18803 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18804 | |
| 18805 | HttpRequestInfo request; |
| 18806 | request.method = "POST"; |
| 18807 | request.url = GURL("http://www.foo.com/"); |
| 18808 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18809 | request.traffic_annotation = |
| 18810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18814 | // Send headers successfully, but get an error while sending the body. |
| 18815 | MockWrite data_writes[] = { |
| 18816 | MockWrite("POST / HTTP/1.1\r\n" |
| 18817 | "Host: www.foo.com\r\n" |
| 18818 | "Connection: keep-alive\r\n" |
| 18819 | "Content-Length: 3\r\n\r\n"), |
| 18820 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18821 | }; |
| 18822 | |
| 18823 | MockRead data_reads[] = { |
| 18824 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 18825 | MockRead(SYNCHRONOUS, OK), |
| 18826 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18827 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18829 | |
| 18830 | TestCompletionCallback callback; |
| 18831 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18832 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18834 | |
| 18835 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18836 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18837 | } |
| 18838 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18839 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18840 | |
| 18841 | namespace { |
| 18842 | |
| 18843 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 18844 | headers->SetHeader("Connection", "Upgrade"); |
| 18845 | headers->SetHeader("Upgrade", "websocket"); |
| 18846 | headers->SetHeader("Origin", "http://www.example.org"); |
| 18847 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18848 | } |
| 18849 | |
| 18850 | } // namespace |
| 18851 | |
| 18852 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18853 | for (bool secure : {true, false}) { |
| 18854 | MockWrite data_writes[] = { |
| 18855 | MockWrite("GET / HTTP/1.1\r\n" |
| 18856 | "Host: www.example.org\r\n" |
| 18857 | "Connection: Upgrade\r\n" |
| 18858 | "Upgrade: websocket\r\n" |
| 18859 | "Origin: http://www.example.org\r\n" |
| 18860 | "Sec-WebSocket-Version: 13\r\n" |
| 18861 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18862 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18863 | "client_max_window_bits\r\n\r\n")}; |
| 18864 | |
| 18865 | MockRead data_reads[] = { |
| 18866 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18867 | "Upgrade: websocket\r\n" |
| 18868 | "Connection: Upgrade\r\n" |
| 18869 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 18870 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18871 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18872 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18873 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18874 | if (secure) |
| 18875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18876 | |
| 18877 | HttpRequestInfo request; |
| 18878 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18879 | request.url = |
| 18880 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 18881 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18882 | request.traffic_annotation = |
| 18883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18884 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18885 | TestWebSocketHandshakeStreamCreateHelper |
| 18886 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18887 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18889 | HttpNetworkTransaction trans(LOW, session.get()); |
| 18890 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18891 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18892 | |
| 18893 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18896 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18897 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 18898 | ASSERT_TRUE(stream_request); |
| 18899 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 18900 | stream_request->websocket_handshake_stream_create_helper()); |
| 18901 | |
| 18902 | rv = callback.WaitForResult(); |
| 18903 | EXPECT_THAT(rv, IsOk()); |
| 18904 | |
| 18905 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 18906 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18907 | } |
| 18908 | } |
| 18909 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18910 | // Verify that proxy headers are not sent to the destination server when |
| 18911 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18912 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18913 | HttpRequestInfo request; |
| 18914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18915 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18916 | request.traffic_annotation = |
| 18917 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18918 | AddWebSocketHeaders(&request.extra_headers); |
| 18919 | |
| 18920 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18921 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 18922 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18923 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18924 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18926 | |
| 18927 | // Since a proxy is configured, try to establish a tunnel. |
| 18928 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18929 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18930 | "Host: www.example.org:443\r\n" |
| 18931 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18932 | |
| 18933 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18934 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18935 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18936 | "Host: www.example.org:443\r\n" |
| 18937 | "Proxy-Connection: keep-alive\r\n" |
| 18938 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18939 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18940 | MockWrite("GET / HTTP/1.1\r\n" |
| 18941 | "Host: www.example.org\r\n" |
| 18942 | "Connection: Upgrade\r\n" |
| 18943 | "Upgrade: websocket\r\n" |
| 18944 | "Origin: http://www.example.org\r\n" |
| 18945 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18946 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18947 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18948 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18949 | |
| 18950 | // The proxy responds to the connect with a 407, using a persistent |
| 18951 | // connection. |
| 18952 | MockRead data_reads[] = { |
| 18953 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18954 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 18955 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 18956 | "Content-Length: 0\r\n" |
| 18957 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18958 | |
| 18959 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18960 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18961 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18962 | "Upgrade: websocket\r\n" |
| 18963 | "Connection: Upgrade\r\n" |
| 18964 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18965 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18966 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18968 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18970 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18971 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 18972 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18973 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18974 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18975 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 18976 | &websocket_stream_create_helper); |
| 18977 | |
| 18978 | { |
| 18979 | TestCompletionCallback callback; |
| 18980 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18981 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18983 | |
| 18984 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18985 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18986 | } |
| 18987 | |
| 18988 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18989 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18990 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18991 | EXPECT_EQ(407, response->headers->response_code()); |
| 18992 | |
| 18993 | { |
| 18994 | TestCompletionCallback callback; |
| 18995 | |
| 18996 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 18997 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18999 | |
| 19000 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19001 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19002 | } |
| 19003 | |
| 19004 | response = trans->GetResponseInfo(); |
| 19005 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 19006 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19007 | |
| 19008 | EXPECT_EQ(101, response->headers->response_code()); |
| 19009 | |
| 19010 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 19011 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19012 | } |
| 19013 | |
| 19014 | // Verify that proxy headers are not sent to the destination server when |
| 19015 | // establishing a tunnel for an insecure WebSocket connection. |
| 19016 | // This requires the authentication info to be injected into the auth cache |
| 19017 | // due to crbug.com/395064 |
| 19018 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19019 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19020 | HttpRequestInfo request; |
| 19021 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 19022 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19023 | request.traffic_annotation = |
| 19024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19025 | AddWebSocketHeaders(&request.extra_headers); |
| 19026 | |
| 19027 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 19028 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19029 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 19030 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19031 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19033 | |
| 19034 | MockWrite data_writes[] = { |
| 19035 | // Try to establish a tunnel for the WebSocket connection, with |
| 19036 | // credentials. Because WebSockets have a separate set of socket pools, |
| 19037 | // they cannot and will not use the same TCP/IP connection as the |
| 19038 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19039 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 19040 | "Host: www.example.org:80\r\n" |
| 19041 | "Proxy-Connection: keep-alive\r\n" |
| 19042 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19043 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19044 | MockWrite("GET / HTTP/1.1\r\n" |
| 19045 | "Host: www.example.org\r\n" |
| 19046 | "Connection: Upgrade\r\n" |
| 19047 | "Upgrade: websocket\r\n" |
| 19048 | "Origin: http://www.example.org\r\n" |
| 19049 | "Sec-WebSocket-Version: 13\r\n" |
| 19050 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 19051 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 19052 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19053 | |
| 19054 | MockRead data_reads[] = { |
| 19055 | // HTTP CONNECT with credentials. |
| 19056 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19057 | |
| 19058 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19059 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 19060 | "Upgrade: websocket\r\n" |
| 19061 | "Connection: Upgrade\r\n" |
| 19062 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19063 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19064 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19065 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19066 | |
| 19067 | session->http_auth_cache()->Add( |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 19068 | GURL("http://myproxy:70/"), HttpAuth::AUTH_PROXY, "MyRealm1", |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 19069 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey(), |
| 19070 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19071 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19072 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 19073 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 19074 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19075 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19076 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 19077 | &websocket_stream_create_helper); |
| 19078 | |
| 19079 | TestCompletionCallback callback; |
| 19080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19081 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19083 | |
| 19084 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19085 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19086 | |
| 19087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19088 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 19089 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19090 | |
| 19091 | EXPECT_EQ(101, response->headers->response_code()); |
| 19092 | |
| 19093 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 19094 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19095 | } |
| 19096 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 19097 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 19098 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 19099 | for (bool secure : {true, false}) { |
| 19100 | SCOPED_TRACE(secure); |
| 19101 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19102 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 19103 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19104 | session_deps_.enable_quic = true; |
| 19105 | |
| 19106 | HttpRequestInfo request; |
| 19107 | request.url = |
| 19108 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 19109 | AddWebSocketHeaders(&request.extra_headers); |
| 19110 | request.traffic_annotation = |
| 19111 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19112 | |
| 19113 | TestWebSocketHandshakeStreamCreateHelper |
| 19114 | websocket_handshake_stream_create_helper; |
| 19115 | |
| 19116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19117 | HttpNetworkTransaction trans(LOW, session.get()); |
| 19118 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 19119 | &websocket_handshake_stream_create_helper); |
| 19120 | |
| 19121 | TestCompletionCallback callback; |
| 19122 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19124 | |
| 19125 | rv = callback.WaitForResult(); |
| 19126 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 19127 | } |
| 19128 | } |
| 19129 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19130 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 19131 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19132 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19133 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19134 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19135 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19136 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19137 | |
| 19138 | HttpRequestInfo request; |
| 19139 | request.method = "POST"; |
| 19140 | request.url = GURL("http://www.foo.com/"); |
| 19141 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19142 | request.traffic_annotation = |
| 19143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19144 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19147 | MockWrite data_writes[] = { |
| 19148 | MockWrite("POST / HTTP/1.1\r\n" |
| 19149 | "Host: www.foo.com\r\n" |
| 19150 | "Connection: keep-alive\r\n" |
| 19151 | "Content-Length: 3\r\n\r\n"), |
| 19152 | MockWrite("foo"), |
| 19153 | }; |
| 19154 | |
| 19155 | MockRead data_reads[] = { |
| 19156 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 19157 | MockRead(SYNCHRONOUS, OK), |
| 19158 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19159 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19160 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19161 | |
| 19162 | TestCompletionCallback callback; |
| 19163 | |
| 19164 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19165 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19166 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19167 | |
| 19168 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19169 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19170 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19171 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 19172 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19173 | } |
| 19174 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19175 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19176 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19177 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19178 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19179 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19180 | |
| 19181 | HttpRequestInfo request; |
| 19182 | request.method = "POST"; |
| 19183 | request.url = GURL("http://www.foo.com/"); |
| 19184 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19185 | request.traffic_annotation = |
| 19186 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19187 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19189 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19190 | MockWrite data_writes[] = { |
| 19191 | MockWrite("POST / HTTP/1.1\r\n" |
| 19192 | "Host: www.foo.com\r\n" |
| 19193 | "Connection: keep-alive\r\n" |
| 19194 | "Content-Length: 3\r\n\r\n"), |
| 19195 | MockWrite("foo"), |
| 19196 | }; |
| 19197 | |
| 19198 | MockRead data_reads[] = { |
| 19199 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 19200 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 19201 | MockRead(SYNCHRONOUS, OK), |
| 19202 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19203 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19205 | |
| 19206 | TestCompletionCallback callback; |
| 19207 | |
| 19208 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19209 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19210 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19211 | |
| 19212 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19213 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19214 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19215 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 19216 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19217 | } |
| 19218 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19219 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19220 | ChunkedUploadDataStream upload_data_stream(0); |
| 19221 | |
| 19222 | HttpRequestInfo request; |
| 19223 | request.method = "POST"; |
| 19224 | request.url = GURL("http://www.foo.com/"); |
| 19225 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19226 | request.traffic_annotation = |
| 19227 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19228 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19230 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19231 | // Send headers successfully, but get an error while sending the body. |
| 19232 | MockWrite data_writes[] = { |
| 19233 | MockWrite("POST / HTTP/1.1\r\n" |
| 19234 | "Host: www.foo.com\r\n" |
| 19235 | "Connection: keep-alive\r\n" |
| 19236 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 19237 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 19238 | }; |
| 19239 | |
| 19240 | MockRead data_reads[] = { |
| 19241 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 19242 | MockRead(SYNCHRONOUS, OK), |
| 19243 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19244 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19245 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19246 | |
| 19247 | TestCompletionCallback callback; |
| 19248 | |
| 19249 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19250 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19251 | |
| 19252 | base::RunLoop().RunUntilIdle(); |
| 19253 | upload_data_stream.AppendData("f", 1, false); |
| 19254 | |
| 19255 | base::RunLoop().RunUntilIdle(); |
| 19256 | upload_data_stream.AppendData("oo", 2, true); |
| 19257 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19258 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19259 | |
| 19260 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19261 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19262 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19263 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 19264 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19265 | } |
| 19266 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19267 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 19268 | const std::string& accept_encoding, |
| 19269 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19270 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19271 | bool should_match) { |
| 19272 | HttpRequestInfo request; |
| 19273 | request.method = "GET"; |
| 19274 | request.url = GURL("http://www.foo.com/"); |
| 19275 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 19276 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19277 | request.traffic_annotation = |
| 19278 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19279 | |
| 19280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 19281 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19282 | // Send headers successfully, but get an error while sending the body. |
| 19283 | MockWrite data_writes[] = { |
| 19284 | MockWrite("GET / HTTP/1.1\r\n" |
| 19285 | "Host: www.foo.com\r\n" |
| 19286 | "Connection: keep-alive\r\n" |
| 19287 | "Accept-Encoding: "), |
| 19288 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 19289 | }; |
| 19290 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19291 | std::string response_code = "200 OK"; |
| 19292 | std::string extra; |
| 19293 | if (!location.empty()) { |
| 19294 | response_code = "301 Redirect\r\nLocation: "; |
| 19295 | response_code.append(location); |
| 19296 | } |
| 19297 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19298 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19299 | MockRead("HTTP/1.0 "), |
| 19300 | MockRead(response_code.data()), |
| 19301 | MockRead("\r\nContent-Encoding: "), |
| 19302 | MockRead(content_encoding.data()), |
| 19303 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19304 | MockRead(SYNCHRONOUS, OK), |
| 19305 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19306 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19307 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 19308 | |
| 19309 | TestCompletionCallback callback; |
| 19310 | |
| 19311 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19313 | |
| 19314 | rv = callback.WaitForResult(); |
| 19315 | if (should_match) { |
| 19316 | EXPECT_THAT(rv, IsOk()); |
| 19317 | } else { |
| 19318 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 19319 | } |
| 19320 | } |
| 19321 | |
| 19322 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19323 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19324 | } |
| 19325 | |
| 19326 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19327 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 19328 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19329 | } |
| 19330 | |
| 19331 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 19332 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19333 | "", false); |
| 19334 | } |
| 19335 | |
| 19336 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 19337 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 19338 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19339 | } |
| 19340 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19341 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 19342 | ProxyConfig proxy_config; |
| 19343 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 19344 | proxy_config.set_pac_mandatory(true); |
| 19345 | MockAsyncProxyResolver resolver; |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19346 | session_deps_.proxy_resolution_service.reset( |
| 19347 | new ConfiguredProxyResolutionService( |
| 19348 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 19349 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 19350 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19351 | |
| 19352 | HttpRequestInfo request; |
| 19353 | request.method = "GET"; |
| 19354 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19355 | request.traffic_annotation = |
| 19356 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19357 | |
| 19358 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19359 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19360 | |
| 19361 | TestCompletionCallback callback; |
| 19362 | |
| 19363 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19364 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19365 | EXPECT_THAT(callback.WaitForResult(), |
| 19366 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 19367 | } |
| 19368 | |
| 19369 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 19370 | ProxyConfig proxy_config; |
| 19371 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 19372 | proxy_config.set_pac_mandatory(true); |
| 19373 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 19374 | new MockAsyncProxyResolverFactory(false); |
| 19375 | MockAsyncProxyResolver resolver; |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19376 | session_deps_.proxy_resolution_service.reset( |
| 19377 | new ConfiguredProxyResolutionService( |
| 19378 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 19379 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 19380 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19381 | HttpRequestInfo request; |
| 19382 | request.method = "GET"; |
| 19383 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19384 | request.traffic_annotation = |
| 19385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19386 | |
| 19387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19389 | |
| 19390 | TestCompletionCallback callback; |
| 19391 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19393 | |
| 19394 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 19395 | ERR_FAILED, &resolver); |
| 19396 | EXPECT_THAT(callback.WaitForResult(), |
| 19397 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 19398 | } |
| 19399 | |
| 19400 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 19401 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19402 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 19403 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19404 | session_deps_.enable_quic = false; |
| 19405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19406 | |
| 19407 | HttpRequestInfo request; |
| 19408 | request.method = "GET"; |
| 19409 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19410 | request.traffic_annotation = |
| 19411 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19412 | |
| 19413 | TestCompletionCallback callback; |
| 19414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19415 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19416 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19417 | |
| 19418 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 19419 | } |
| 19420 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19421 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19422 | // Reporting tests |
| 19423 | |
| 19424 | #if BUILDFLAG(ENABLE_REPORTING) |
| 19425 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 19426 | protected: |
| 19427 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19428 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19429 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 19430 | &clock_, &tick_clock_, ReportingPolicy()); |
| 19431 | test_reporting_context_ = test_reporting_context.get(); |
| 19432 | session_deps_.reporting_service = |
| 19433 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 19434 | } |
| 19435 | |
| 19436 | TestReportingContext* reporting_context() const { |
| 19437 | return test_reporting_context_; |
| 19438 | } |
| 19439 | |
| 19440 | void clear_reporting_service() { |
| 19441 | session_deps_.reporting_service.reset(); |
| 19442 | test_reporting_context_ = nullptr; |
| 19443 | } |
| 19444 | |
| 19445 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19446 | void RequestPolicy(CertStatus cert_status = 0) { |
| 19447 | HttpRequestInfo request; |
| 19448 | request.method = "GET"; |
| 19449 | request.url = GURL(url_); |
| 19450 | request.traffic_annotation = |
| 19451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19452 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19453 | MockWrite data_writes[] = { |
| 19454 | MockWrite("GET / HTTP/1.1\r\n" |
| 19455 | "Host: www.example.org\r\n" |
| 19456 | "Connection: keep-alive\r\n\r\n"), |
| 19457 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19458 | MockRead data_reads[] = { |
| 19459 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19460 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 19461 | "\"endpoints\": [{\"url\": " |
| 19462 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 19463 | MockRead("\r\n"), |
| 19464 | MockRead("hello world"), |
| 19465 | MockRead(SYNCHRONOUS, OK), |
| 19466 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19467 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19468 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19469 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19470 | |
| 19471 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19472 | if (request.url.SchemeIsCryptographic()) { |
| 19473 | ssl.ssl_info.cert = |
| 19474 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19475 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19476 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19477 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19478 | } |
| 19479 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19480 | TestCompletionCallback callback; |
| 19481 | auto session = CreateSession(&session_deps_); |
| 19482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19483 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19484 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19485 | } |
| 19486 | |
| 19487 | protected: |
| 19488 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19489 | |
| 19490 | private: |
| 19491 | TestReportingContext* test_reporting_context_; |
| 19492 | }; |
| 19493 | |
| 19494 | TEST_F(HttpNetworkTransactionReportingTest, |
| 19495 | DontProcessReportToHeaderNoService) { |
| 19496 | base::HistogramTester histograms; |
| 19497 | clear_reporting_service(); |
| 19498 | RequestPolicy(); |
| 19499 | histograms.ExpectBucketCount( |
| 19500 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 19501 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 19502 | } |
| 19503 | |
| 19504 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 19505 | base::HistogramTester histograms; |
| 19506 | url_ = "http://www.example.org/"; |
| 19507 | RequestPolicy(); |
| 19508 | histograms.ExpectBucketCount( |
| 19509 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 19510 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 19511 | } |
| 19512 | |
| 19513 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 19514 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 19515 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 19516 | const ReportingEndpoint endpoint = |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 19517 | reporting_context()->cache()->GetEndpointForTesting( |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame^] | 19518 | ReportingEndpointGroupKey( |
| 19519 | NetworkIsolationKey(), |
| 19520 | url::Origin::Create(GURL("https://www.example.org/")), "nel"), |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 19521 | GURL("https://www.example.org/upload/")); |
| 19522 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19523 | } |
| 19524 | |
| 19525 | TEST_F(HttpNetworkTransactionReportingTest, |
| 19526 | DontProcessReportToHeaderInvalidHttps) { |
| 19527 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19528 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 19529 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19530 | histograms.ExpectBucketCount( |
| 19531 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 19532 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 19533 | } |
| 19534 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19535 | |
| 19536 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19537 | // Network Error Logging tests |
| 19538 | |
| 19539 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19540 | namespace { |
| 19541 | |
| 19542 | const char kUserAgent[] = "Mozilla/1.0"; |
| 19543 | const char kReferrer[] = "https://www.referrer.org/"; |
| 19544 | |
| 19545 | } // namespace |
| 19546 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19547 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 19548 | : public HttpNetworkTransactionTest { |
| 19549 | protected: |
| 19550 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19551 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19552 | auto network_error_logging_service = |
| 19553 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 19554 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 19555 | session_deps_.network_error_logging_service = |
| 19556 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19557 | |
| 19558 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 19559 | extra_headers_.SetHeader("Referer", kReferrer); |
| 19560 | |
| 19561 | request_.method = "GET"; |
| 19562 | request_.url = GURL(url_); |
| 19563 | request_.extra_headers = extra_headers_; |
| 19564 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 19565 | request_.traffic_annotation = |
| 19566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19567 | } |
| 19568 | |
| 19569 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 19570 | return test_network_error_logging_service_; |
| 19571 | } |
| 19572 | |
| 19573 | void clear_network_error_logging_service() { |
| 19574 | session_deps_.network_error_logging_service.reset(); |
| 19575 | test_network_error_logging_service_ = nullptr; |
| 19576 | } |
| 19577 | |
| 19578 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19579 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19580 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19581 | MockWrite data_writes[] = { |
| 19582 | MockWrite("GET / HTTP/1.1\r\n" |
| 19583 | "Host: www.example.org\r\n" |
| 19584 | "Connection: keep-alive\r\n"), |
| 19585 | MockWrite(ASYNC, extra_header_string.data(), |
| 19586 | extra_header_string.size()), |
| 19587 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19588 | MockRead data_reads[] = { |
| 19589 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19590 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 19591 | MockRead("\r\n"), |
| 19592 | MockRead("hello world"), |
| 19593 | MockRead(SYNCHRONOUS, OK), |
| 19594 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19595 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19596 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19597 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19598 | |
| 19599 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19600 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19601 | ssl.ssl_info.cert = |
| 19602 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19603 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19604 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19606 | } |
| 19607 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19608 | TestCompletionCallback callback; |
| 19609 | auto session = CreateSession(&session_deps_); |
| 19610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19611 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 19612 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19613 | |
| 19614 | std::string response_data; |
| 19615 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 19616 | EXPECT_EQ("hello world", response_data); |
| 19617 | } |
| 19618 | |
| 19619 | void CheckReport(size_t index, |
| 19620 | int status_code, |
| 19621 | int error_type, |
| 19622 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 19623 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 19624 | |
| 19625 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19626 | network_error_logging_service()->errors()[index]; |
| 19627 | EXPECT_EQ(url_, error.uri); |
| 19628 | EXPECT_EQ(kReferrer, error.referrer); |
| 19629 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 19630 | EXPECT_EQ(server_ip, error.server_ip); |
| 19631 | EXPECT_EQ("http/1.1", error.protocol); |
| 19632 | EXPECT_EQ("GET", error.method); |
| 19633 | EXPECT_EQ(status_code, error.status_code); |
| 19634 | EXPECT_EQ(error_type, error.type); |
| 19635 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19636 | } |
| 19637 | |
| 19638 | protected: |
| 19639 | std::string url_ = "https://www.example.org/"; |
| 19640 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19641 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19642 | HttpRequestHeaders extra_headers_; |
| 19643 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19644 | |
| 19645 | private: |
| 19646 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 19647 | }; |
| 19648 | |
| 19649 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19650 | DontProcessNelHeaderNoService) { |
| 19651 | base::HistogramTester histograms; |
| 19652 | clear_network_error_logging_service(); |
| 19653 | RequestPolicy(); |
| 19654 | histograms.ExpectBucketCount( |
| 19655 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 19656 | NetworkErrorLoggingService::HeaderOutcome:: |
| 19657 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 19658 | 1); |
| 19659 | } |
| 19660 | |
| 19661 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19662 | DontProcessNelHeaderHttp) { |
| 19663 | base::HistogramTester histograms; |
| 19664 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19665 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19666 | RequestPolicy(); |
| 19667 | histograms.ExpectBucketCount( |
| 19668 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 19669 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 19670 | } |
| 19671 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19672 | // Don't set NEL policies received on a proxied connection. |
| 19673 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19674 | DontProcessNelHeaderProxy) { |
| 19675 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19676 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19677 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 19678 | RecordingBoundTestNetLog log; |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19679 | session_deps_.net_log = log.bound().net_log(); |
| 19680 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19681 | |
| 19682 | HttpRequestInfo request; |
| 19683 | request.method = "GET"; |
| 19684 | request.url = GURL("https://www.example.org/"); |
| 19685 | request.traffic_annotation = |
| 19686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19687 | |
| 19688 | // Since we have proxy, should try to establish tunnel. |
| 19689 | MockWrite data_writes1[] = { |
| 19690 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19691 | "Host: www.example.org:443\r\n" |
| 19692 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19693 | |
| 19694 | MockWrite("GET / HTTP/1.1\r\n" |
| 19695 | "Host: www.example.org\r\n" |
| 19696 | "Connection: keep-alive\r\n\r\n"), |
| 19697 | }; |
| 19698 | |
| 19699 | MockRead data_reads1[] = { |
| 19700 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19701 | |
| 19702 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19703 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 19704 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19705 | MockRead("Content-Length: 100\r\n\r\n"), |
| 19706 | MockRead(SYNCHRONOUS, OK), |
| 19707 | }; |
| 19708 | |
| 19709 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19710 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19711 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19712 | ssl.ssl_info.cert = |
| 19713 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19714 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 19715 | ssl.ssl_info.cert_status = 0; |
| 19716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19717 | |
| 19718 | TestCompletionCallback callback1; |
| 19719 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19720 | |
| 19721 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 19722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19723 | |
| 19724 | rv = callback1.WaitForResult(); |
| 19725 | EXPECT_THAT(rv, IsOk()); |
| 19726 | |
| 19727 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 19728 | ASSERT_TRUE(response); |
| 19729 | EXPECT_EQ(200, response->headers->response_code()); |
| 19730 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 19731 | |
| 19732 | // No NEL header was set. |
| 19733 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 19734 | } |
| 19735 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19736 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 19737 | RequestPolicy(); |
| 19738 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19739 | const auto& header = network_error_logging_service()->headers()[0]; |
| 19740 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 19741 | header.origin); |
| 19742 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 19743 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 19744 | } |
| 19745 | |
| 19746 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19747 | DontProcessNelHeaderInvalidHttps) { |
| 19748 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19749 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 19750 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19751 | histograms.ExpectBucketCount( |
| 19752 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 19753 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 19754 | 1); |
| 19755 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19756 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19757 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19758 | RequestPolicy(); |
| 19759 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19760 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19761 | } |
| 19762 | |
| 19763 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19764 | CreateReportErrorAfterStart) { |
| 19765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19766 | auto trans = |
| 19767 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19768 | |
| 19769 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 19770 | StaticSocketDataProvider data; |
| 19771 | data.set_connect_data(mock_connect); |
| 19772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19773 | |
| 19774 | TestCompletionCallback callback; |
| 19775 | |
| 19776 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19777 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 19778 | |
| 19779 | trans.reset(); |
| 19780 | |
| 19781 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19782 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 19783 | IPAddress() /* server_ip */); |
| 19784 | } |
| 19785 | |
| 19786 | // Same as above except the error is ASYNC |
| 19787 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19788 | CreateReportErrorAfterStartAsync) { |
| 19789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19790 | auto trans = |
| 19791 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19792 | |
| 19793 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 19794 | StaticSocketDataProvider data; |
| 19795 | data.set_connect_data(mock_connect); |
| 19796 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19797 | |
| 19798 | TestCompletionCallback callback; |
| 19799 | |
| 19800 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19801 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 19802 | |
| 19803 | trans.reset(); |
| 19804 | |
| 19805 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19806 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 19807 | IPAddress() /* server_ip */); |
| 19808 | } |
| 19809 | |
| 19810 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19811 | CreateReportReadBodyError) { |
| 19812 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19813 | MockWrite data_writes[] = { |
| 19814 | MockWrite("GET / HTTP/1.1\r\n" |
| 19815 | "Host: www.example.org\r\n" |
| 19816 | "Connection: keep-alive\r\n"), |
| 19817 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19818 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19819 | MockRead data_reads[] = { |
| 19820 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19821 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 19822 | MockRead("hello world"), |
| 19823 | MockRead(SYNCHRONOUS, OK), |
| 19824 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19825 | |
| 19826 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19827 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19828 | |
| 19829 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19831 | |
| 19832 | // Log start time |
| 19833 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19834 | |
| 19835 | TestCompletionCallback callback; |
| 19836 | auto session = CreateSession(&session_deps_); |
| 19837 | auto trans = |
| 19838 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19839 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19840 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19841 | |
| 19842 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19843 | ASSERT_TRUE(response); |
| 19844 | |
| 19845 | EXPECT_TRUE(response->headers); |
| 19846 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19847 | |
| 19848 | std::string response_data; |
| 19849 | rv = ReadTransaction(trans.get(), &response_data); |
| 19850 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 19851 | |
| 19852 | trans.reset(); |
| 19853 | |
| 19854 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19855 | |
| 19856 | CheckReport(0 /* index */, 200 /* status_code */, |
| 19857 | ERR_CONTENT_LENGTH_MISMATCH); |
| 19858 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19859 | network_error_logging_service()->errors()[0]; |
| 19860 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 19861 | } |
| 19862 | |
| 19863 | // Same as above except the final read is ASYNC. |
| 19864 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19865 | CreateReportReadBodyErrorAsync) { |
| 19866 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19867 | MockWrite data_writes[] = { |
| 19868 | MockWrite("GET / HTTP/1.1\r\n" |
| 19869 | "Host: www.example.org\r\n" |
| 19870 | "Connection: keep-alive\r\n"), |
| 19871 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19872 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19873 | MockRead data_reads[] = { |
| 19874 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19875 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 19876 | MockRead("hello world"), |
| 19877 | MockRead(ASYNC, OK), |
| 19878 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19879 | |
| 19880 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19881 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19882 | |
| 19883 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19885 | |
| 19886 | // Log start time |
| 19887 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19888 | |
| 19889 | TestCompletionCallback callback; |
| 19890 | auto session = CreateSession(&session_deps_); |
| 19891 | auto trans = |
| 19892 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19893 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19894 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19895 | |
| 19896 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19897 | ASSERT_TRUE(response); |
| 19898 | |
| 19899 | EXPECT_TRUE(response->headers); |
| 19900 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19901 | |
| 19902 | std::string response_data; |
| 19903 | rv = ReadTransaction(trans.get(), &response_data); |
| 19904 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 19905 | |
| 19906 | trans.reset(); |
| 19907 | |
| 19908 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19909 | |
| 19910 | CheckReport(0 /* index */, 200 /* status_code */, |
| 19911 | ERR_CONTENT_LENGTH_MISMATCH); |
| 19912 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19913 | network_error_logging_service()->errors()[0]; |
| 19914 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 19915 | } |
| 19916 | |
| 19917 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19918 | CreateReportRestartWithAuth) { |
| 19919 | std::string extra_header_string = extra_headers_.ToString(); |
| 19920 | static const base::TimeDelta kSleepDuration = |
| 19921 | base::TimeDelta::FromMilliseconds(10); |
| 19922 | |
| 19923 | MockWrite data_writes1[] = { |
| 19924 | MockWrite("GET / HTTP/1.1\r\n" |
| 19925 | "Host: www.example.org\r\n" |
| 19926 | "Connection: keep-alive\r\n"), |
| 19927 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19928 | }; |
| 19929 | |
| 19930 | MockRead data_reads1[] = { |
| 19931 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 19932 | // Give a couple authenticate options (only the middle one is actually |
| 19933 | // supported). |
| 19934 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 19935 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19936 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 19937 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19938 | // Large content-length -- won't matter, as connection will be reset. |
| 19939 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 19940 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 19941 | }; |
| 19942 | |
| 19943 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19944 | // be issuing -- the final header line contains the credentials. |
| 19945 | MockWrite data_writes2[] = { |
| 19946 | MockWrite("GET / HTTP/1.1\r\n" |
| 19947 | "Host: www.example.org\r\n" |
| 19948 | "Connection: keep-alive\r\n" |
| 19949 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 19950 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19951 | }; |
| 19952 | |
| 19953 | // Lastly, the server responds with the actual content. |
| 19954 | MockRead data_reads2[] = { |
| 19955 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19956 | MockRead("hello world"), |
| 19957 | MockRead(SYNCHRONOUS, OK), |
| 19958 | }; |
| 19959 | |
| 19960 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19961 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19962 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19963 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19964 | |
| 19965 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19966 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19967 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19969 | |
| 19970 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19971 | base::TimeTicks restart_time; |
| 19972 | |
| 19973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19974 | auto trans = |
| 19975 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19976 | |
| 19977 | TestCompletionCallback callback1; |
| 19978 | |
| 19979 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19980 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19981 | |
| 19982 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19983 | |
| 19984 | TestCompletionCallback callback2; |
| 19985 | |
| 19986 | // Wait 10 ms then restart with auth |
| 19987 | FastForwardBy(kSleepDuration); |
| 19988 | restart_time = base::TimeTicks::Now(); |
| 19989 | rv = |
| 19990 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19991 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19992 | |
| 19993 | std::string response_data; |
| 19994 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19995 | EXPECT_EQ("hello world", response_data); |
| 19996 | |
| 19997 | trans.reset(); |
| 19998 | |
| 19999 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 20000 | // retry. Note that we don't report the error draining the body, as the first |
| 20001 | // request already generated a report for the auth challenge. |
| 20002 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 20003 | |
| 20004 | // Check error report contents |
| 20005 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 20006 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 20007 | |
| 20008 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 20009 | network_error_logging_service()->errors()[0]; |
| 20010 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 20011 | network_error_logging_service()->errors()[1]; |
| 20012 | |
| 20013 | // Sanity-check elapsed time values |
| 20014 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 20015 | // Check that the start time is refreshed when restarting with auth. |
| 20016 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 20017 | } |
| 20018 | |
| 20019 | // Same as above, except draining the body before restarting fails |
| 20020 | // asynchronously. |
| 20021 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20022 | CreateReportRestartWithAuthAsync) { |
| 20023 | std::string extra_header_string = extra_headers_.ToString(); |
| 20024 | static const base::TimeDelta kSleepDuration = |
| 20025 | base::TimeDelta::FromMilliseconds(10); |
| 20026 | |
| 20027 | MockWrite data_writes1[] = { |
| 20028 | MockWrite("GET / HTTP/1.1\r\n" |
| 20029 | "Host: www.example.org\r\n" |
| 20030 | "Connection: keep-alive\r\n"), |
| 20031 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20032 | }; |
| 20033 | |
| 20034 | MockRead data_reads1[] = { |
| 20035 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 20036 | // Give a couple authenticate options (only the middle one is actually |
| 20037 | // supported). |
| 20038 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 20039 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 20040 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 20041 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 20042 | // Large content-length -- won't matter, as connection will be reset. |
| 20043 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 20044 | MockRead(ASYNC, ERR_FAILED), |
| 20045 | }; |
| 20046 | |
| 20047 | // After calling trans->RestartWithAuth(), this is the request we should |
| 20048 | // be issuing -- the final header line contains the credentials. |
| 20049 | MockWrite data_writes2[] = { |
| 20050 | MockWrite("GET / HTTP/1.1\r\n" |
| 20051 | "Host: www.example.org\r\n" |
| 20052 | "Connection: keep-alive\r\n" |
| 20053 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 20054 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20055 | }; |
| 20056 | |
| 20057 | // Lastly, the server responds with the actual content. |
| 20058 | MockRead data_reads2[] = { |
| 20059 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 20060 | MockRead("hello world"), |
| 20061 | MockRead(SYNCHRONOUS, OK), |
| 20062 | }; |
| 20063 | |
| 20064 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20065 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 20066 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20067 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20068 | |
| 20069 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20070 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20071 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20073 | |
| 20074 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 20075 | base::TimeTicks restart_time; |
| 20076 | |
| 20077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20078 | auto trans = |
| 20079 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20080 | |
| 20081 | TestCompletionCallback callback1; |
| 20082 | |
| 20083 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20084 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20085 | |
| 20086 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20087 | |
| 20088 | TestCompletionCallback callback2; |
| 20089 | |
| 20090 | // Wait 10 ms then restart with auth |
| 20091 | FastForwardBy(kSleepDuration); |
| 20092 | restart_time = base::TimeTicks::Now(); |
| 20093 | rv = |
| 20094 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 20095 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20096 | |
| 20097 | std::string response_data; |
| 20098 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20099 | EXPECT_EQ("hello world", response_data); |
| 20100 | |
| 20101 | trans.reset(); |
| 20102 | |
| 20103 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 20104 | // retry. Note that we don't report the error draining the body, as the first |
| 20105 | // request already generated a report for the auth challenge. |
| 20106 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 20107 | |
| 20108 | // Check error report contents |
| 20109 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 20110 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 20111 | |
| 20112 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 20113 | network_error_logging_service()->errors()[0]; |
| 20114 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 20115 | network_error_logging_service()->errors()[1]; |
| 20116 | |
| 20117 | // Sanity-check elapsed time values |
| 20118 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 20119 | // Check that the start time is refreshed when restarting with auth. |
| 20120 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 20121 | } |
| 20122 | |
| 20123 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20124 | CreateReportRetryKeepAliveConnectionReset) { |
| 20125 | std::string extra_header_string = extra_headers_.ToString(); |
| 20126 | MockWrite data_writes1[] = { |
| 20127 | MockWrite("GET / HTTP/1.1\r\n" |
| 20128 | "Host: www.example.org\r\n" |
| 20129 | "Connection: keep-alive\r\n"), |
| 20130 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20131 | MockWrite("GET / HTTP/1.1\r\n" |
| 20132 | "Host: www.example.org\r\n" |
| 20133 | "Connection: keep-alive\r\n"), |
| 20134 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20135 | }; |
| 20136 | |
| 20137 | MockRead data_reads1[] = { |
| 20138 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20139 | MockRead("hello"), |
| 20140 | // Connection is reset |
| 20141 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 20142 | }; |
| 20143 | |
| 20144 | // Successful retry |
| 20145 | MockRead data_reads2[] = { |
| 20146 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20147 | MockRead("world"), |
| 20148 | MockRead(ASYNC, OK), |
| 20149 | }; |
| 20150 | |
| 20151 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20152 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 20153 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20154 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20155 | |
| 20156 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20157 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20158 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20159 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20160 | |
| 20161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20162 | auto trans1 = |
| 20163 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20164 | |
| 20165 | TestCompletionCallback callback1; |
| 20166 | |
| 20167 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20168 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20169 | |
| 20170 | std::string response_data; |
| 20171 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 20172 | EXPECT_EQ("hello", response_data); |
| 20173 | |
| 20174 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20175 | |
| 20176 | auto trans2 = |
| 20177 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20178 | |
| 20179 | TestCompletionCallback callback2; |
| 20180 | |
| 20181 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 20182 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20183 | |
| 20184 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 20185 | EXPECT_EQ("world", response_data); |
| 20186 | |
| 20187 | trans1.reset(); |
| 20188 | trans2.reset(); |
| 20189 | |
| 20190 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 20191 | // the second request, then an OK report from the successful retry. |
| 20192 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 20193 | |
| 20194 | // Check error report contents |
| 20195 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20196 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 20197 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 20198 | } |
| 20199 | |
| 20200 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20201 | CreateReportRetryKeepAlive408) { |
| 20202 | std::string extra_header_string = extra_headers_.ToString(); |
| 20203 | MockWrite data_writes1[] = { |
| 20204 | MockWrite("GET / HTTP/1.1\r\n" |
| 20205 | "Host: www.example.org\r\n" |
| 20206 | "Connection: keep-alive\r\n"), |
| 20207 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20208 | MockWrite("GET / HTTP/1.1\r\n" |
| 20209 | "Host: www.example.org\r\n" |
| 20210 | "Connection: keep-alive\r\n"), |
| 20211 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20212 | }; |
| 20213 | |
| 20214 | MockRead data_reads1[] = { |
| 20215 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20216 | MockRead("hello"), |
| 20217 | // 408 Request Timeout |
| 20218 | MockRead(SYNCHRONOUS, |
| 20219 | "HTTP/1.1 408 Request Timeout\r\n" |
| 20220 | "Connection: Keep-Alive\r\n" |
| 20221 | "Content-Length: 6\r\n\r\n" |
| 20222 | "Pickle"), |
| 20223 | }; |
| 20224 | |
| 20225 | // Successful retry |
| 20226 | MockRead data_reads2[] = { |
| 20227 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20228 | MockRead("world"), |
| 20229 | MockRead(ASYNC, OK), |
| 20230 | }; |
| 20231 | |
| 20232 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20233 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 20234 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20235 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20236 | |
| 20237 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20239 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20241 | |
| 20242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20243 | auto trans1 = |
| 20244 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20245 | |
| 20246 | TestCompletionCallback callback1; |
| 20247 | |
| 20248 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20249 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20250 | |
| 20251 | std::string response_data; |
| 20252 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 20253 | EXPECT_EQ("hello", response_data); |
| 20254 | |
| 20255 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20256 | |
| 20257 | auto trans2 = |
| 20258 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20259 | |
| 20260 | TestCompletionCallback callback2; |
| 20261 | |
| 20262 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 20263 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20264 | |
| 20265 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 20266 | EXPECT_EQ("world", response_data); |
| 20267 | |
| 20268 | trans1.reset(); |
| 20269 | trans2.reset(); |
| 20270 | |
| 20271 | // One 200 report from first request, then a 408 report from |
| 20272 | // the second request, then a 200 report from the successful retry. |
| 20273 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 20274 | |
| 20275 | // Check error report contents |
| 20276 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20277 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 20278 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 20279 | } |
| 20280 | |
| 20281 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20282 | CreateReportRetry421WithoutConnectionPooling) { |
| 20283 | // Two hosts resolve to the same IP address. |
| 20284 | const std::string ip_addr = "1.2.3.4"; |
| 20285 | IPAddress ip; |
| 20286 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 20287 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 20288 | |
| 20289 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 20290 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 20291 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 20292 | |
| 20293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20294 | |
| 20295 | // Two requests on the first connection. |
| 20296 | spdy::SpdySerializedFrame req1( |
| 20297 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 20298 | spdy_util_.UpdateWithStreamDestruction(1); |
| 20299 | spdy::SpdySerializedFrame req2( |
| 20300 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 20301 | spdy::SpdySerializedFrame rst( |
| 20302 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 20303 | MockWrite writes1[] = { |
| 20304 | CreateMockWrite(req1, 0), |
| 20305 | CreateMockWrite(req2, 3), |
| 20306 | CreateMockWrite(rst, 6), |
| 20307 | }; |
| 20308 | |
| 20309 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 20310 | spdy::SpdySerializedFrame resp1( |
| 20311 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 20312 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 20313 | spdy::SpdyHeaderBlock response_headers; |
| 20314 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 20315 | spdy::SpdySerializedFrame resp2( |
| 20316 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 20317 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 20318 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 20319 | |
| 20320 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 20321 | SequencedSocketData data1(connect1, reads1, writes1); |
| 20322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20323 | |
| 20324 | AddSSLSocketData(); |
| 20325 | |
| 20326 | // Retry the second request on a second connection. |
| 20327 | SpdyTestUtil spdy_util2; |
| 20328 | spdy::SpdySerializedFrame req3( |
| 20329 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 20330 | MockWrite writes2[] = { |
| 20331 | CreateMockWrite(req3, 0), |
| 20332 | }; |
| 20333 | |
| 20334 | spdy::SpdySerializedFrame resp3( |
| 20335 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 20336 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 20337 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 20338 | MockRead(ASYNC, 0, 3)}; |
| 20339 | |
| 20340 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 20341 | SequencedSocketData data2(connect2, reads2, writes2); |
| 20342 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20343 | |
| 20344 | AddSSLSocketData(); |
| 20345 | |
| 20346 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 20347 | int rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 20348 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 20349 | base::nullopt); |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 20350 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20351 | |
| 20352 | HttpRequestInfo request1; |
| 20353 | request1.method = "GET"; |
| 20354 | request1.url = GURL("https://www.example.org/"); |
| 20355 | request1.load_flags = 0; |
| 20356 | request1.traffic_annotation = |
| 20357 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20358 | auto trans1 = |
| 20359 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20360 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 20361 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20362 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 20363 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20364 | |
| 20365 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 20366 | ASSERT_TRUE(response); |
| 20367 | ASSERT_TRUE(response->headers); |
| 20368 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 20369 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 20370 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 20371 | std::string response_data; |
| 20372 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 20373 | EXPECT_EQ("hello!", response_data); |
| 20374 | |
| 20375 | trans1.reset(); |
| 20376 | |
| 20377 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20378 | |
| 20379 | HttpRequestInfo request2; |
| 20380 | request2.method = "GET"; |
| 20381 | request2.url = GURL("https://mail.example.org/"); |
| 20382 | request2.load_flags = 0; |
| 20383 | request2.traffic_annotation = |
| 20384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20385 | auto trans2 = |
| 20386 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20387 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 20388 | RecordingBoundTestNetLog log; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20389 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 20390 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20391 | |
| 20392 | response = trans2->GetResponseInfo(); |
| 20393 | ASSERT_TRUE(response); |
| 20394 | ASSERT_TRUE(response->headers); |
| 20395 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 20396 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 20397 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 20398 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 20399 | EXPECT_EQ("hello!", response_data); |
| 20400 | |
| 20401 | trans2.reset(); |
| 20402 | |
| 20403 | // One 200 report from the first request, then a 421 report from the |
| 20404 | // second request, then a 200 report from the successful retry. |
| 20405 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 20406 | |
| 20407 | // Check error report contents |
| 20408 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 20409 | network_error_logging_service()->errors()[0]; |
| 20410 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 20411 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 20412 | EXPECT_EQ("", error1.user_agent); |
| 20413 | EXPECT_EQ(ip, error1.server_ip); |
| 20414 | EXPECT_EQ("h2", error1.protocol); |
| 20415 | EXPECT_EQ("GET", error1.method); |
| 20416 | EXPECT_EQ(200, error1.status_code); |
| 20417 | EXPECT_EQ(OK, error1.type); |
| 20418 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 20419 | |
| 20420 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 20421 | network_error_logging_service()->errors()[1]; |
| 20422 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 20423 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 20424 | EXPECT_EQ("", error2.user_agent); |
| 20425 | EXPECT_EQ(ip, error2.server_ip); |
| 20426 | EXPECT_EQ("h2", error2.protocol); |
| 20427 | EXPECT_EQ("GET", error2.method); |
| 20428 | EXPECT_EQ(421, error2.status_code); |
| 20429 | EXPECT_EQ(OK, error2.type); |
| 20430 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 20431 | |
| 20432 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 20433 | network_error_logging_service()->errors()[2]; |
| 20434 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 20435 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 20436 | EXPECT_EQ("", error3.user_agent); |
| 20437 | EXPECT_EQ(ip, error3.server_ip); |
| 20438 | EXPECT_EQ("h2", error3.protocol); |
| 20439 | EXPECT_EQ("GET", error3.method); |
| 20440 | EXPECT_EQ(200, error3.status_code); |
| 20441 | EXPECT_EQ(OK, error3.type); |
| 20442 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20443 | } |
| 20444 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 20445 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20446 | CreateReportCancelAfterStart) { |
| 20447 | StaticSocketDataProvider data; |
| 20448 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 20449 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20450 | |
| 20451 | TestCompletionCallback callback; |
| 20452 | auto session = CreateSession(&session_deps_); |
| 20453 | auto trans = |
| 20454 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20455 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20456 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 20457 | |
| 20458 | // Cancel after start. |
| 20459 | trans.reset(); |
| 20460 | |
| 20461 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20462 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 20463 | IPAddress() /* server_ip */); |
| 20464 | } |
| 20465 | |
| 20466 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20467 | CreateReportCancelBeforeReadingBody) { |
| 20468 | std::string extra_header_string = extra_headers_.ToString(); |
| 20469 | MockWrite data_writes[] = { |
| 20470 | MockWrite("GET / HTTP/1.1\r\n" |
| 20471 | "Host: www.example.org\r\n" |
| 20472 | "Connection: keep-alive\r\n"), |
| 20473 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20474 | }; |
| 20475 | MockRead data_reads[] = { |
| 20476 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 20477 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 20478 | }; |
| 20479 | |
| 20480 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20481 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20482 | |
| 20483 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20485 | |
| 20486 | TestCompletionCallback callback; |
| 20487 | auto session = CreateSession(&session_deps_); |
| 20488 | auto trans = |
| 20489 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20490 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20491 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20492 | |
| 20493 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20494 | ASSERT_TRUE(response); |
| 20495 | |
| 20496 | EXPECT_TRUE(response->headers); |
| 20497 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 20498 | |
| 20499 | // Cancel before reading the body. |
| 20500 | trans.reset(); |
| 20501 | |
| 20502 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20503 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 20504 | } |
| 20505 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20506 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20507 | RequestPolicy(); |
| 20508 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 20509 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20510 | |
| 20511 | // Make HTTP request |
| 20512 | std::string extra_header_string = extra_headers_.ToString(); |
| 20513 | MockRead data_reads[] = { |
| 20514 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 20515 | MockRead("hello world"), |
| 20516 | MockRead(SYNCHRONOUS, OK), |
| 20517 | }; |
| 20518 | MockWrite data_writes[] = { |
| 20519 | MockWrite("GET / HTTP/1.1\r\n" |
| 20520 | "Host: www.example.org\r\n" |
| 20521 | "Connection: keep-alive\r\n"), |
| 20522 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20523 | }; |
| 20524 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 20525 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20526 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20527 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20528 | // Insecure url |
| 20529 | url_ = "http://www.example.org/"; |
| 20530 | request_.url = GURL(url_); |
| 20531 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20532 | TestCompletionCallback callback; |
| 20533 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20534 | auto trans = |
| 20535 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20536 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20537 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20538 | |
| 20539 | std::string response_data; |
| 20540 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20541 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20542 | |
| 20543 | // Insecure request does not generate a report |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20544 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20545 | } |
| 20546 | |
| 20547 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20548 | DontCreateReportHttpError) { |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20549 | RequestPolicy(); |
| 20550 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 20551 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20552 | |
| 20553 | // Make HTTP request that fails |
| 20554 | MockRead data_reads[] = { |
| 20555 | MockRead("hello world"), |
| 20556 | MockRead(SYNCHRONOUS, OK), |
| 20557 | }; |
| 20558 | |
| 20559 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 20560 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20561 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20562 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 20563 | request_.url = GURL(url_); |
| 20564 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20565 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20566 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20567 | auto trans = |
| 20568 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20569 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20570 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20571 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 20572 | |
| 20573 | // Insecure request does not generate a report, regardless of existence of a |
| 20574 | // policy for the origin. |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20575 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20576 | } |
| 20577 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 20578 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 20579 | // proxy. |
| 20580 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 20581 | HttpRequestInfo request; |
| 20582 | request.method = "GET"; |
| 20583 | request.url = GURL("https://www.example.org/"); |
| 20584 | request.traffic_annotation = |
| 20585 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20586 | |
| 20587 | // Configure against proxy server "myproxy:70". |
| 20588 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 20589 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 20590 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20592 | |
| 20593 | // Since we have proxy, should try to establish tunnel. |
| 20594 | MockWrite data_writes1[] = { |
| 20595 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20596 | "Host: www.example.org:443\r\n" |
| 20597 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 20598 | }; |
| 20599 | |
| 20600 | // The proxy responds to the connect with a 407, using a non-persistent |
| 20601 | // connection. |
| 20602 | MockRead data_reads1[] = { |
| 20603 | // No credentials. |
| 20604 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 20605 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 20606 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 20607 | }; |
| 20608 | |
| 20609 | MockWrite data_writes2[] = { |
| 20610 | // After calling trans->RestartWithAuth(), this is the request we should |
| 20611 | // be issuing -- the final header line contains the credentials. |
| 20612 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20613 | "Host: www.example.org:443\r\n" |
| 20614 | "Proxy-Connection: keep-alive\r\n" |
| 20615 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 20616 | |
| 20617 | MockWrite("GET / HTTP/1.1\r\n" |
| 20618 | "Host: www.example.org\r\n" |
| 20619 | "Connection: keep-alive\r\n\r\n"), |
| 20620 | }; |
| 20621 | |
| 20622 | MockRead data_reads2[] = { |
| 20623 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 20624 | |
| 20625 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20626 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 20627 | MockRead("Content-Length: 5\r\n\r\n"), |
| 20628 | MockRead(SYNCHRONOUS, "hello"), |
| 20629 | }; |
| 20630 | |
| 20631 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20632 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20633 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 20634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20635 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20637 | |
| 20638 | TestCompletionCallback callback1; |
| 20639 | |
| 20640 | auto trans = |
| 20641 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20642 | |
| 20643 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 20644 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20645 | |
| 20646 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20647 | EXPECT_EQ(407, response->headers->response_code()); |
| 20648 | |
| 20649 | std::string response_data; |
| 20650 | rv = ReadTransaction(trans.get(), &response_data); |
| 20651 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 20652 | |
| 20653 | // No NEL report is generated for the 407. |
| 20654 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 20655 | |
| 20656 | TestCompletionCallback callback2; |
| 20657 | |
| 20658 | rv = |
| 20659 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 20660 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20661 | |
| 20662 | response = trans->GetResponseInfo(); |
| 20663 | EXPECT_EQ(200, response->headers->response_code()); |
| 20664 | |
| 20665 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20666 | EXPECT_EQ("hello", response_data); |
| 20667 | |
| 20668 | trans.reset(); |
| 20669 | |
| 20670 | // No NEL report is generated because we are behind a proxy. |
| 20671 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 20672 | } |
| 20673 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20674 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20675 | ReportContainsUploadDepth) { |
| 20676 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20677 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20678 | RequestPolicy(); |
| 20679 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20680 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20681 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20682 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 20683 | } |
| 20684 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20685 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 20686 | std::string extra_header_string = extra_headers_.ToString(); |
| 20687 | static const base::TimeDelta kSleepDuration = |
| 20688 | base::TimeDelta::FromMilliseconds(10); |
| 20689 | |
| 20690 | std::vector<MockWrite> data_writes = { |
| 20691 | MockWrite(ASYNC, 0, |
| 20692 | "GET / HTTP/1.1\r\n" |
| 20693 | "Host: www.example.org\r\n" |
| 20694 | "Connection: keep-alive\r\n"), |
| 20695 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 20696 | }; |
| 20697 | |
| 20698 | std::vector<MockRead> data_reads = { |
| 20699 | // Write one byte of the status line, followed by a pause. |
| 20700 | MockRead(ASYNC, 2, "H"), |
| 20701 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 20702 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 20703 | MockRead(ASYNC, 5, "hello world"), |
| 20704 | MockRead(SYNCHRONOUS, OK, 6), |
| 20705 | }; |
| 20706 | |
| 20707 | SequencedSocketData data(data_reads, data_writes); |
| 20708 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20709 | |
| 20710 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20712 | |
| 20713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20714 | |
| 20715 | auto trans = |
| 20716 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20717 | |
| 20718 | TestCompletionCallback callback; |
| 20719 | |
| 20720 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20721 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20722 | |
| 20723 | data.RunUntilPaused(); |
| 20724 | ASSERT_TRUE(data.IsPaused()); |
| 20725 | FastForwardBy(kSleepDuration); |
| 20726 | data.Resume(); |
| 20727 | |
| 20728 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20729 | |
| 20730 | std::string response_data; |
| 20731 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20732 | EXPECT_EQ("hello world", response_data); |
| 20733 | |
| 20734 | trans.reset(); |
| 20735 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20736 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20737 | |
| 20738 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20739 | |
| 20740 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20741 | network_error_logging_service()->errors()[0]; |
| 20742 | |
| 20743 | // Sanity-check elapsed time in error report |
| 20744 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20745 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20746 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 20747 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 20748 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 20749 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 20750 | HttpRequestInfo request; |
| 20751 | request.method = "GET"; |
| 20752 | request.url = GURL("http://example.org/"); |
| 20753 | |
| 20754 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 20755 | |
| 20756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 20758 | TestCompletionCallback callback1; |
| 20759 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 20760 | |
| 20761 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 20762 | } |
| 20763 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20764 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20765 | static const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20766 | HttpRequestInfo request; |
| 20767 | request.method = "GET"; |
| 20768 | request.url = GURL("https://www.example.org/"); |
| 20769 | request.traffic_annotation = |
| 20770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20771 | |
| 20772 | MockWrite data_writes[] = { |
| 20773 | MockWrite("GET / HTTP/1.1\r\n" |
| 20774 | "Host: www.example.org\r\n" |
| 20775 | "Connection: keep-alive\r\n\r\n"), |
| 20776 | }; |
| 20777 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20778 | MockRead data_reads[] = { |
| 20779 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20780 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20781 | MockRead(SYNCHRONOUS, "1"), |
| 20782 | }; |
| 20783 | |
| 20784 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20786 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20787 | ssl.connect_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20788 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20789 | ssl.confirm_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20790 | session_deps_.enable_early_data = true; |
| 20791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20792 | |
| 20793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20794 | |
| 20795 | TestCompletionCallback callback; |
| 20796 | auto trans = |
| 20797 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20798 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20799 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20800 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20802 | |
| 20803 | rv = callback.WaitForResult(); |
| 20804 | EXPECT_THAT(rv, IsOk()); |
| 20805 | |
| 20806 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20807 | ASSERT_TRUE(response); |
| 20808 | ASSERT_TRUE(response->headers); |
| 20809 | EXPECT_EQ(200, response->headers->response_code()); |
| 20810 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20811 | |
| 20812 | // Check that ConfirmHandshake wasn't called. |
| 20813 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 20814 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 20815 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20816 | // The handshake time should include the time it took to run Connect(), but |
| 20817 | // not ConfirmHandshake(). |
| 20818 | LoadTimingInfo load_timing_info; |
| 20819 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 20820 | EXPECT_EQ(load_timing_info.connect_timing.connect_start, start_time); |
| 20821 | EXPECT_EQ(load_timing_info.connect_timing.ssl_start, start_time); |
| 20822 | EXPECT_EQ(load_timing_info.connect_timing.ssl_end, start_time + kDelay); |
| 20823 | EXPECT_EQ(load_timing_info.connect_timing.connect_end, start_time + kDelay); |
| 20824 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20825 | trans.reset(); |
| 20826 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 20827 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20828 | } |
| 20829 | |
| 20830 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20831 | static const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20832 | HttpRequestInfo request; |
| 20833 | request.method = "POST"; |
| 20834 | request.url = GURL("https://www.example.org/"); |
| 20835 | request.traffic_annotation = |
| 20836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20837 | |
| 20838 | MockWrite data_writes[] = { |
| 20839 | MockWrite(SYNCHRONOUS, |
| 20840 | "POST / HTTP/1.1\r\n" |
| 20841 | "Host: www.example.org\r\n" |
| 20842 | "Connection: keep-alive\r\n" |
| 20843 | "Content-Length: 0\r\n\r\n"), |
| 20844 | }; |
| 20845 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20846 | MockRead data_reads[] = { |
| 20847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20848 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20849 | MockRead(SYNCHRONOUS, "1"), |
| 20850 | }; |
| 20851 | |
| 20852 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20853 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20854 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20855 | ssl.connect_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20856 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20857 | ssl.confirm_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20858 | session_deps_.enable_early_data = true; |
| 20859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20860 | |
| 20861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20862 | |
| 20863 | TestCompletionCallback callback; |
| 20864 | auto trans = |
| 20865 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20866 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20867 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20868 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20870 | |
| 20871 | rv = callback.WaitForResult(); |
| 20872 | EXPECT_THAT(rv, IsOk()); |
| 20873 | |
| 20874 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20875 | ASSERT_TRUE(response); |
| 20876 | ASSERT_TRUE(response->headers); |
| 20877 | EXPECT_EQ(200, response->headers->response_code()); |
| 20878 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20879 | |
| 20880 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20881 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20882 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20883 | // The handshake time should include the time it took to run Connect(), but |
| 20884 | // not ConfirmHandshake(). If ConfirmHandshake() returns synchronously, we |
| 20885 | // assume the connection did not negotiate 0-RTT or the handshake was already |
| 20886 | // confirmed. |
| 20887 | LoadTimingInfo load_timing_info; |
| 20888 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 20889 | EXPECT_EQ(load_timing_info.connect_timing.connect_start, start_time); |
| 20890 | EXPECT_EQ(load_timing_info.connect_timing.ssl_start, start_time); |
| 20891 | EXPECT_EQ(load_timing_info.connect_timing.ssl_end, start_time + kDelay); |
| 20892 | EXPECT_EQ(load_timing_info.connect_timing.connect_end, start_time + kDelay); |
| 20893 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20894 | trans.reset(); |
| 20895 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 20896 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20897 | } |
| 20898 | |
| 20899 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 20900 | HttpRequestInfo request; |
| 20901 | request.method = "POST"; |
| 20902 | request.url = GURL("https://www.example.org/"); |
| 20903 | request.traffic_annotation = |
| 20904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20905 | |
| 20906 | MockWrite data_writes[] = { |
| 20907 | MockWrite(ASYNC, |
| 20908 | "POST / HTTP/1.1\r\n" |
| 20909 | "Host: www.example.org\r\n" |
| 20910 | "Connection: keep-alive\r\n" |
| 20911 | "Content-Length: 0\r\n\r\n"), |
| 20912 | }; |
| 20913 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20914 | MockRead data_reads[] = { |
| 20915 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20916 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20917 | MockRead(SYNCHRONOUS, "1"), |
| 20918 | }; |
| 20919 | |
| 20920 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20921 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20922 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20923 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 20924 | session_deps_.enable_early_data = true; |
| 20925 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20926 | |
| 20927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20928 | |
| 20929 | TestCompletionCallback callback; |
| 20930 | auto trans = |
| 20931 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20932 | |
| 20933 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20935 | |
| 20936 | rv = callback.WaitForResult(); |
| 20937 | EXPECT_THAT(rv, IsOk()); |
| 20938 | |
| 20939 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20940 | ASSERT_TRUE(response); |
| 20941 | ASSERT_TRUE(response->headers); |
| 20942 | EXPECT_EQ(200, response->headers->response_code()); |
| 20943 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20944 | |
| 20945 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20946 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20947 | |
| 20948 | trans.reset(); |
| 20949 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 20950 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20951 | } |
| 20952 | |
| 20953 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20954 | static const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20955 | HttpRequestInfo request; |
| 20956 | request.method = "POST"; |
| 20957 | request.url = GURL("https://www.example.org/"); |
| 20958 | request.traffic_annotation = |
| 20959 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20960 | |
| 20961 | MockWrite data_writes[] = { |
| 20962 | MockWrite(SYNCHRONOUS, |
| 20963 | "POST / HTTP/1.1\r\n" |
| 20964 | "Host: www.example.org\r\n" |
| 20965 | "Connection: keep-alive\r\n" |
| 20966 | "Content-Length: 0\r\n\r\n"), |
| 20967 | }; |
| 20968 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20969 | MockRead data_reads[] = { |
| 20970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20971 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20972 | MockRead(SYNCHRONOUS, "1"), |
| 20973 | }; |
| 20974 | |
| 20975 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20976 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20977 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20978 | ssl.connect_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20979 | ssl.confirm = MockConfirm(ASYNC, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20980 | ssl.confirm_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20981 | session_deps_.enable_early_data = true; |
| 20982 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20983 | |
| 20984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20985 | |
| 20986 | TestCompletionCallback callback; |
| 20987 | auto trans = |
| 20988 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20989 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 20990 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20991 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20993 | |
| 20994 | rv = callback.WaitForResult(); |
| 20995 | EXPECT_THAT(rv, IsOk()); |
| 20996 | |
| 20997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20998 | ASSERT_TRUE(response); |
| 20999 | ASSERT_TRUE(response->headers); |
| 21000 | EXPECT_EQ(200, response->headers->response_code()); |
| 21001 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21002 | |
| 21003 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21004 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21005 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21006 | // The handshake time should include the time it took to run Connect() and |
| 21007 | // ConfirmHandshake(). |
| 21008 | LoadTimingInfo load_timing_info; |
| 21009 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 21010 | EXPECT_EQ(load_timing_info.connect_timing.connect_start, start_time); |
| 21011 | EXPECT_EQ(load_timing_info.connect_timing.ssl_start, start_time); |
| 21012 | EXPECT_EQ(load_timing_info.connect_timing.ssl_end, start_time + 2 * kDelay); |
| 21013 | EXPECT_EQ(load_timing_info.connect_timing.connect_end, |
| 21014 | start_time + 2 * kDelay); |
| 21015 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21016 | trans.reset(); |
| 21017 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21018 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21019 | } |
| 21020 | |
| 21021 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 21022 | HttpRequestInfo request; |
| 21023 | request.method = "POST"; |
| 21024 | request.url = GURL("https://www.example.org/"); |
| 21025 | request.traffic_annotation = |
| 21026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21027 | |
| 21028 | MockWrite data_writes[] = { |
| 21029 | MockWrite(ASYNC, |
| 21030 | "POST / HTTP/1.1\r\n" |
| 21031 | "Host: www.example.org\r\n" |
| 21032 | "Connection: keep-alive\r\n" |
| 21033 | "Content-Length: 0\r\n\r\n"), |
| 21034 | }; |
| 21035 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21036 | MockRead data_reads[] = { |
| 21037 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21038 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21039 | MockRead(SYNCHRONOUS, "1"), |
| 21040 | }; |
| 21041 | |
| 21042 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21043 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21044 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21045 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 21046 | session_deps_.enable_early_data = true; |
| 21047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21048 | |
| 21049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21050 | |
| 21051 | TestCompletionCallback callback; |
| 21052 | auto trans = |
| 21053 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21054 | |
| 21055 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21057 | |
| 21058 | rv = callback.WaitForResult(); |
| 21059 | EXPECT_THAT(rv, IsOk()); |
| 21060 | |
| 21061 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21062 | ASSERT_TRUE(response); |
| 21063 | ASSERT_TRUE(response->headers); |
| 21064 | EXPECT_EQ(200, response->headers->response_code()); |
| 21065 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21066 | |
| 21067 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21068 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21069 | |
| 21070 | trans.reset(); |
| 21071 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21072 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21073 | } |
| 21074 | |
David Benjamin | fb97693 | 2019-05-15 13:39:15 | [diff] [blame] | 21075 | // 0-RTT rejects are handled at HttpNetworkTransaction. |
| 21076 | TEST_F(HttpNetworkTransactionTest, ZeroRTTReject) { |
| 21077 | enum class RejectType { |
| 21078 | kRead, |
| 21079 | kWrite, |
| 21080 | kConfirm, |
| 21081 | }; |
| 21082 | |
| 21083 | for (RejectType type : |
| 21084 | {RejectType::kRead, RejectType::kWrite, RejectType::kConfirm}) { |
| 21085 | SCOPED_TRACE(static_cast<int>(type)); |
| 21086 | for (Error reject_error : |
| 21087 | {ERR_EARLY_DATA_REJECTED, ERR_WRONG_VERSION_ON_EARLY_DATA}) { |
| 21088 | SCOPED_TRACE(reject_error); |
| 21089 | session_deps_.socket_factory = |
| 21090 | std::make_unique<MockClientSocketFactory>(); |
| 21091 | |
| 21092 | HttpRequestInfo request; |
| 21093 | request.method = type == RejectType::kConfirm ? "POST" : "GET"; |
| 21094 | request.url = GURL("https://www.example.org/"); |
| 21095 | request.traffic_annotation = |
| 21096 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21097 | |
| 21098 | // The first request fails. |
| 21099 | std::vector<MockWrite> data1_writes; |
| 21100 | std::vector<MockRead> data1_reads; |
| 21101 | SSLSocketDataProvider ssl1(SYNCHRONOUS, OK); |
| 21102 | switch (type) { |
| 21103 | case RejectType::kRead: |
| 21104 | data1_writes.emplace_back( |
| 21105 | "GET / HTTP/1.1\r\n" |
| 21106 | "Host: www.example.org\r\n" |
| 21107 | "Connection: keep-alive\r\n\r\n"); |
| 21108 | data1_reads.emplace_back(ASYNC, reject_error); |
| 21109 | // Cause ConfirmHandshake to hang (it should not be called). |
| 21110 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 21111 | break; |
| 21112 | case RejectType::kWrite: |
| 21113 | data1_writes.emplace_back(ASYNC, reject_error); |
| 21114 | // Cause ConfirmHandshake to hang (it should not be called). |
| 21115 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 21116 | break; |
| 21117 | case RejectType::kConfirm: |
| 21118 | // The request never gets far enough to read or write. |
| 21119 | ssl1.confirm = MockConfirm(ASYNC, reject_error); |
| 21120 | break; |
| 21121 | } |
| 21122 | |
| 21123 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 21124 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21125 | session_deps_.enable_early_data = true; |
| 21126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 21127 | |
| 21128 | // The retry succeeds. |
| 21129 | // |
| 21130 | // TODO(https://crbug.com/950705): If |reject_error| is |
| 21131 | // ERR_EARLY_DATA_REJECTED, the retry should happen over the same socket. |
| 21132 | MockWrite data2_writes[] = { |
| 21133 | request.method == "POST" |
| 21134 | ? MockWrite("POST / HTTP/1.1\r\n" |
| 21135 | "Host: www.example.org\r\n" |
| 21136 | "Connection: keep-alive\r\n" |
| 21137 | "Content-Length: 0\r\n\r\n") |
| 21138 | : MockWrite("GET / HTTP/1.1\r\n" |
| 21139 | "Host: www.example.org\r\n" |
| 21140 | "Connection: keep-alive\r\n\r\n"), |
| 21141 | }; |
| 21142 | |
| 21143 | MockRead data2_reads[] = { |
| 21144 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21145 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21146 | MockRead(SYNCHRONOUS, "1"), |
| 21147 | }; |
| 21148 | |
| 21149 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 21150 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21151 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 21152 | ssl2.confirm = MockConfirm(ASYNC, OK); |
| 21153 | session_deps_.enable_early_data = true; |
| 21154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 21155 | |
| 21156 | std::unique_ptr<HttpNetworkSession> session( |
| 21157 | CreateSession(&session_deps_)); |
| 21158 | |
| 21159 | TestCompletionCallback callback; |
| 21160 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21161 | session.get()); |
| 21162 | |
| 21163 | EXPECT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 21164 | NetLogWithSource())), |
| 21165 | IsOk()); |
| 21166 | |
| 21167 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21168 | ASSERT_TRUE(response); |
| 21169 | ASSERT_TRUE(response->headers); |
| 21170 | EXPECT_EQ(200, response->headers->response_code()); |
| 21171 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21172 | } |
| 21173 | } |
| 21174 | } |
| 21175 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21176 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 21177 | HttpRequestInfo request; |
| 21178 | request.method = "POST"; |
| 21179 | request.url = GURL("https://www.example.org/"); |
| 21180 | request.traffic_annotation = |
| 21181 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21182 | |
| 21183 | MockWrite data_writes[] = { |
| 21184 | MockWrite("POST / HTTP/1.1\r\n" |
| 21185 | "Host: www.example.org\r\n" |
| 21186 | "Connection: keep-alive\r\n" |
| 21187 | "Content-Length: 0\r\n\r\n"), |
| 21188 | }; |
| 21189 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21190 | MockRead data_reads[] = { |
| 21191 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21192 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21193 | MockRead(SYNCHRONOUS, "1"), |
| 21194 | }; |
| 21195 | |
| 21196 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21197 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21198 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21199 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 21200 | session_deps_.enable_early_data = true; |
| 21201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21202 | |
| 21203 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21204 | |
| 21205 | TestCompletionCallback callback; |
| 21206 | auto trans = |
| 21207 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21208 | |
| 21209 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21211 | |
| 21212 | rv = callback.WaitForResult(); |
| 21213 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 21214 | |
| 21215 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21216 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21217 | |
| 21218 | trans.reset(); |
| 21219 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21220 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21221 | } |
| 21222 | |
| 21223 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 21224 | HttpRequestInfo request; |
| 21225 | request.method = "POST"; |
| 21226 | request.url = GURL("https://www.example.org/"); |
| 21227 | request.traffic_annotation = |
| 21228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21229 | |
| 21230 | MockWrite data_writes[] = { |
| 21231 | MockWrite("POST / HTTP/1.1\r\n" |
| 21232 | "Host: www.example.org\r\n" |
| 21233 | "Connection: keep-alive\r\n" |
| 21234 | "Content-Length: 0\r\n\r\n"), |
| 21235 | }; |
| 21236 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21237 | MockRead data_reads[] = { |
| 21238 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21239 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21240 | MockRead(SYNCHRONOUS, "1"), |
| 21241 | }; |
| 21242 | |
| 21243 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21244 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21245 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21246 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 21247 | session_deps_.enable_early_data = true; |
| 21248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21249 | |
| 21250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21251 | |
| 21252 | TestCompletionCallback callback; |
| 21253 | auto trans = |
| 21254 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21255 | |
| 21256 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21258 | |
| 21259 | rv = callback.WaitForResult(); |
| 21260 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 21261 | |
| 21262 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21263 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21264 | |
| 21265 | trans.reset(); |
| 21266 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21267 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21268 | } |
| 21269 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21270 | // Test the proxy and origin server each requesting both TLS client certificates |
| 21271 | // and HTTP auth. This is a regression test for https://crbug.com/946406. |
| 21272 | TEST_F(HttpNetworkTransactionTest, AuthEverything) { |
| 21273 | // Note these hosts must match the CheckBasic*Auth() functions. |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 21274 | session_deps_.proxy_resolution_service = |
| 21275 | ConfiguredProxyResolutionService::CreateFixed( |
| 21276 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21277 | |
| 21278 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21279 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 21280 | |
| 21281 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 21282 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21283 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21284 | ASSERT_TRUE(identity_proxy); |
| 21285 | |
| 21286 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21287 | cert_request_info_origin->host_and_port = |
| 21288 | HostPortPair("www.example.org", 443); |
| 21289 | |
| 21290 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 21291 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21292 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 21293 | ASSERT_TRUE(identity_origin); |
| 21294 | |
| 21295 | HttpRequestInfo request; |
| 21296 | request.method = "GET"; |
| 21297 | request.url = GURL("https://www.example.org/"); |
| 21298 | request.traffic_annotation = |
| 21299 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21300 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21301 | // First, the client connects to the proxy, which requests a client |
| 21302 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21303 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21304 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 21305 | ssl_proxy1.expected_send_client_cert = false; |
| 21306 | StaticSocketDataProvider data1; |
| 21307 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21309 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21310 | // The client responds with a certificate on a new connection. The handshake |
| 21311 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21312 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21313 | ssl_proxy2.expected_send_client_cert = true; |
| 21314 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21315 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21316 | std::vector<MockWrite> mock_writes2; |
| 21317 | std::vector<MockRead> mock_reads2; |
| 21318 | mock_writes2.emplace_back( |
| 21319 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21320 | "Host: www.example.org:443\r\n" |
| 21321 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 21322 | mock_reads2.emplace_back( |
| 21323 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21324 | "Content-Length: 0\r\n" |
| 21325 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21326 | // The client retries with credentials. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21327 | mock_writes2.emplace_back( |
| 21328 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21329 | "Host: www.example.org:443\r\n" |
| 21330 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21331 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21332 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21333 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21334 | // The origin requests client certificates. |
| 21335 | SSLSocketDataProvider ssl_origin2(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21336 | ssl_origin2.cert_request_info = cert_request_info_origin.get(); |
| 21337 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 21338 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 21340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21341 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21342 | // The client responds to the origin client certificate request on a new |
| 21343 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21344 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 21345 | ssl_proxy3.expected_send_client_cert = true; |
| 21346 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 21347 | std::vector<MockWrite> mock_writes3; |
| 21348 | std::vector<MockRead> mock_reads3; |
| 21349 | mock_writes3.emplace_back( |
| 21350 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21351 | "Host: www.example.org:443\r\n" |
| 21352 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21353 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21354 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21355 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21356 | SSLSocketDataProvider ssl_origin3(ASYNC, OK); |
| 21357 | ssl_origin3.expected_send_client_cert = true; |
| 21358 | ssl_origin3.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21359 | // The client sends the origin HTTP request, which results in another HTTP |
| 21360 | // auth request. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21361 | mock_writes3.emplace_back( |
| 21362 | "GET / HTTP/1.1\r\n" |
| 21363 | "Host: www.example.org\r\n" |
| 21364 | "Connection: keep-alive\r\n\r\n"); |
| 21365 | mock_reads3.emplace_back( |
| 21366 | "HTTP/1.1 401 Unauthorized\r\n" |
| 21367 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 21368 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21369 | // The client retries with credentials, and the request finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21370 | mock_writes3.emplace_back( |
| 21371 | "GET / HTTP/1.1\r\n" |
| 21372 | "Host: www.example.org\r\n" |
| 21373 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21374 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21375 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21376 | mock_reads3.emplace_back( |
| 21377 | "HTTP/1.1 200 OK\r\n" |
| 21378 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21379 | // The client makes another request. This should reuse the socket with all |
| 21380 | // credentials cached. |
| 21381 | mock_writes3.emplace_back( |
| 21382 | "GET / HTTP/1.1\r\n" |
| 21383 | "Host: www.example.org\r\n" |
| 21384 | "Connection: keep-alive\r\n" |
| 21385 | // Authenticate as user:pass. |
| 21386 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21387 | mock_reads3.emplace_back( |
| 21388 | "HTTP/1.1 200 OK\r\n" |
| 21389 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21390 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 21391 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 21393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21394 | |
| 21395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21396 | |
| 21397 | // Start the request. |
| 21398 | TestCompletionCallback callback; |
| 21399 | auto trans = |
| 21400 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21401 | int rv = callback.GetResult( |
| 21402 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 21403 | |
| 21404 | // Handle the proxy client certificate challenge. |
| 21405 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21406 | SSLCertRequestInfo* cert_request_info = |
| 21407 | trans->GetResponseInfo()->cert_request_info.get(); |
| 21408 | ASSERT_TRUE(cert_request_info); |
| 21409 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 21410 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21411 | cert_request_info_proxy->host_and_port); |
| 21412 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21413 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 21414 | callback.callback())); |
| 21415 | |
| 21416 | // Handle the proxy HTTP auth challenge. |
| 21417 | ASSERT_THAT(rv, IsOk()); |
| 21418 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 21419 | EXPECT_TRUE( |
| 21420 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21421 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21422 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 21423 | callback.callback())); |
| 21424 | |
| 21425 | // Handle the origin client certificate challenge. |
| 21426 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21427 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 21428 | ASSERT_TRUE(cert_request_info); |
| 21429 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 21430 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21431 | cert_request_info_origin->host_and_port); |
| 21432 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21433 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 21434 | callback.callback())); |
| 21435 | |
| 21436 | // Handle the origin HTTP auth challenge. |
| 21437 | ASSERT_THAT(rv, IsOk()); |
| 21438 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 21439 | EXPECT_TRUE( |
| 21440 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21441 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21442 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 21443 | callback.callback())); |
| 21444 | |
| 21445 | // The request completes. |
| 21446 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21447 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21448 | |
| 21449 | // Make a second request. This time all credentials are cached. |
| 21450 | trans = |
| 21451 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21452 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 21453 | NetLogWithSource())), |
| 21454 | IsOk()); |
| 21455 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21456 | } |
| 21457 | |
| 21458 | // Test the proxy and origin server each requesting both TLS client certificates |
| 21459 | // and HTTP auth and each HTTP auth closing the connection. This is a regression |
| 21460 | // test for https://crbug.com/946406. |
| 21461 | TEST_F(HttpNetworkTransactionTest, AuthEverythingWithConnectClose) { |
| 21462 | // Note these hosts must match the CheckBasic*Auth() functions. |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 21463 | session_deps_.proxy_resolution_service = |
| 21464 | ConfiguredProxyResolutionService::CreateFixed( |
| 21465 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21466 | |
| 21467 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21468 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 21469 | |
| 21470 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 21471 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21472 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21473 | ASSERT_TRUE(identity_proxy); |
| 21474 | |
| 21475 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21476 | cert_request_info_origin->host_and_port = |
| 21477 | HostPortPair("www.example.org", 443); |
| 21478 | |
| 21479 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 21480 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21481 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 21482 | ASSERT_TRUE(identity_origin); |
| 21483 | |
| 21484 | HttpRequestInfo request; |
| 21485 | request.method = "GET"; |
| 21486 | request.url = GURL("https://www.example.org/"); |
| 21487 | request.traffic_annotation = |
| 21488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21489 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21490 | // First, the client connects to the proxy, which requests a client |
| 21491 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21492 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21493 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 21494 | ssl_proxy1.expected_send_client_cert = false; |
| 21495 | StaticSocketDataProvider data1; |
| 21496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21497 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21498 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21499 | // The client responds with a certificate on a new connection. The handshake |
| 21500 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21501 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21502 | ssl_proxy2.expected_send_client_cert = true; |
| 21503 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21504 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21505 | std::vector<MockWrite> mock_writes2; |
| 21506 | std::vector<MockRead> mock_reads2; |
| 21507 | mock_writes2.emplace_back( |
| 21508 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21509 | "Host: www.example.org:443\r\n" |
| 21510 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 21511 | mock_reads2.emplace_back( |
| 21512 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21513 | "Content-Length: 0\r\n" |
| 21514 | "Proxy-Connection: close\r\n" |
| 21515 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 21516 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 21517 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21519 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21520 | // The client retries with credentials on a new connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21521 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 21522 | ssl_proxy3.expected_send_client_cert = true; |
| 21523 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 21524 | std::vector<MockWrite> mock_writes3; |
| 21525 | std::vector<MockRead> mock_reads3; |
| 21526 | mock_writes3.emplace_back( |
| 21527 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21528 | "Host: www.example.org:443\r\n" |
| 21529 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21530 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21531 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21532 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21533 | // The origin requests client certificates. |
| 21534 | SSLSocketDataProvider ssl_origin3(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21535 | ssl_origin3.cert_request_info = cert_request_info_origin.get(); |
| 21536 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 21537 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 21539 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21540 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21541 | // The client responds to the origin client certificate request on a new |
| 21542 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21543 | SSLSocketDataProvider ssl_proxy4(ASYNC, OK); |
| 21544 | ssl_proxy4.expected_send_client_cert = true; |
| 21545 | ssl_proxy4.expected_client_cert = identity_proxy->certificate(); |
| 21546 | std::vector<MockWrite> mock_writes4; |
| 21547 | std::vector<MockRead> mock_reads4; |
| 21548 | mock_writes4.emplace_back( |
| 21549 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21550 | "Host: www.example.org:443\r\n" |
| 21551 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21552 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21553 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21554 | mock_reads4.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21555 | SSLSocketDataProvider ssl_origin4(ASYNC, OK); |
| 21556 | ssl_origin4.expected_send_client_cert = true; |
| 21557 | ssl_origin4.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21558 | // The client sends the origin HTTP request, which results in another HTTP |
| 21559 | // auth request and closed connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21560 | mock_writes4.emplace_back( |
| 21561 | "GET / HTTP/1.1\r\n" |
| 21562 | "Host: www.example.org\r\n" |
| 21563 | "Connection: keep-alive\r\n\r\n"); |
| 21564 | mock_reads4.emplace_back( |
| 21565 | "HTTP/1.1 401 Unauthorized\r\n" |
| 21566 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 21567 | "Connection: close\r\n" |
| 21568 | "Content-Length: 0\r\n\r\n"); |
| 21569 | StaticSocketDataProvider data4(mock_reads4, mock_writes4); |
| 21570 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy4); |
| 21572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin4); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21573 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21574 | // The client retries with credentials on a new connection, and the request |
| 21575 | // finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21576 | SSLSocketDataProvider ssl_proxy5(ASYNC, OK); |
| 21577 | ssl_proxy5.expected_send_client_cert = true; |
| 21578 | ssl_proxy5.expected_client_cert = identity_proxy->certificate(); |
| 21579 | std::vector<MockWrite> mock_writes5; |
| 21580 | std::vector<MockRead> mock_reads5; |
| 21581 | mock_writes5.emplace_back( |
| 21582 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21583 | "Host: www.example.org:443\r\n" |
| 21584 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21585 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21586 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21587 | mock_reads5.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21588 | SSLSocketDataProvider ssl_origin5(ASYNC, OK); |
| 21589 | ssl_origin5.expected_send_client_cert = true; |
| 21590 | ssl_origin5.expected_client_cert = identity_origin->certificate(); |
| 21591 | mock_writes5.emplace_back( |
| 21592 | "GET / HTTP/1.1\r\n" |
| 21593 | "Host: www.example.org\r\n" |
| 21594 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21595 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21596 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21597 | mock_reads5.emplace_back( |
| 21598 | "HTTP/1.1 200 OK\r\n" |
| 21599 | "Connection: close\r\n" |
| 21600 | "Content-Length: 0\r\n\r\n"); |
| 21601 | StaticSocketDataProvider data5(mock_reads5, mock_writes5); |
| 21602 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy5); |
| 21604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin5); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21605 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21606 | // The client makes a second request. This needs yet another connection, but |
| 21607 | // all credentials are cached. |
| 21608 | SSLSocketDataProvider ssl_proxy6(ASYNC, OK); |
| 21609 | ssl_proxy6.expected_send_client_cert = true; |
| 21610 | ssl_proxy6.expected_client_cert = identity_proxy->certificate(); |
| 21611 | std::vector<MockWrite> mock_writes6; |
| 21612 | std::vector<MockRead> mock_reads6; |
| 21613 | mock_writes6.emplace_back( |
| 21614 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21615 | "Host: www.example.org:443\r\n" |
| 21616 | "Proxy-Connection: keep-alive\r\n" |
| 21617 | // Authenticate as proxyuser:proxypass. |
| 21618 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21619 | mock_reads6.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21620 | SSLSocketDataProvider ssl_origin6(ASYNC, OK); |
| 21621 | ssl_origin6.expected_send_client_cert = true; |
| 21622 | ssl_origin6.expected_client_cert = identity_origin->certificate(); |
| 21623 | mock_writes6.emplace_back( |
| 21624 | "GET / HTTP/1.1\r\n" |
| 21625 | "Host: www.example.org\r\n" |
| 21626 | "Connection: keep-alive\r\n" |
| 21627 | // Authenticate as user:pass. |
| 21628 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21629 | mock_reads6.emplace_back( |
| 21630 | "HTTP/1.1 200 OK\r\n" |
| 21631 | "Connection: close\r\n" |
| 21632 | "Content-Length: 0\r\n\r\n"); |
| 21633 | StaticSocketDataProvider data6(mock_reads6, mock_writes6); |
| 21634 | session_deps_.socket_factory->AddSocketDataProvider(&data6); |
| 21635 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy6); |
| 21636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin6); |
| 21637 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21639 | |
| 21640 | // Start the request. |
| 21641 | TestCompletionCallback callback; |
| 21642 | auto trans = |
| 21643 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21644 | int rv = callback.GetResult( |
| 21645 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 21646 | |
| 21647 | // Handle the proxy client certificate challenge. |
| 21648 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21649 | SSLCertRequestInfo* cert_request_info = |
| 21650 | trans->GetResponseInfo()->cert_request_info.get(); |
| 21651 | ASSERT_TRUE(cert_request_info); |
| 21652 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 21653 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21654 | cert_request_info_proxy->host_and_port); |
| 21655 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21656 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 21657 | callback.callback())); |
| 21658 | |
| 21659 | // Handle the proxy HTTP auth challenge. |
| 21660 | ASSERT_THAT(rv, IsOk()); |
| 21661 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 21662 | EXPECT_TRUE( |
| 21663 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21664 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21665 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 21666 | callback.callback())); |
| 21667 | |
| 21668 | // Handle the origin client certificate challenge. |
| 21669 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21670 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 21671 | ASSERT_TRUE(cert_request_info); |
| 21672 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 21673 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21674 | cert_request_info_origin->host_and_port); |
| 21675 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21676 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 21677 | callback.callback())); |
| 21678 | |
| 21679 | // Handle the origin HTTP auth challenge. |
| 21680 | ASSERT_THAT(rv, IsOk()); |
| 21681 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 21682 | EXPECT_TRUE( |
| 21683 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21684 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21685 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 21686 | callback.callback())); |
| 21687 | |
| 21688 | // The request completes. |
| 21689 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21690 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21691 | |
| 21692 | // Make a second request. This time all credentials are cached. |
| 21693 | trans = |
| 21694 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21695 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 21696 | NetLogWithSource())), |
| 21697 | IsOk()); |
| 21698 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21699 | } |
| 21700 | |
| 21701 | // Test the proxy requesting HTTP auth and the server requesting TLS client |
| 21702 | // certificates. This is a regression test for https://crbug.com/946406. |
| 21703 | TEST_F(HttpNetworkTransactionTest, ProxyHTTPAndServerTLSAuth) { |
| 21704 | // Note these hosts must match the CheckBasic*Auth() functions. |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 21705 | session_deps_.proxy_resolution_service = |
| 21706 | ConfiguredProxyResolutionService::CreateFixed( |
| 21707 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21708 | |
| 21709 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21710 | cert_request_info_origin->host_and_port = |
| 21711 | HostPortPair("www.example.org", 443); |
| 21712 | |
| 21713 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 21714 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21715 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 21716 | ASSERT_TRUE(identity_origin); |
| 21717 | |
| 21718 | HttpRequestInfo request; |
| 21719 | request.method = "GET"; |
| 21720 | request.url = GURL("https://www.example.org/"); |
| 21721 | request.traffic_annotation = |
| 21722 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21723 | |
| 21724 | // The client connects to the proxy. The handshake succeeds. |
| 21725 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 21726 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 21727 | std::vector<MockWrite> mock_writes1; |
| 21728 | std::vector<MockRead> mock_reads1; |
| 21729 | mock_writes1.emplace_back( |
| 21730 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21731 | "Host: www.example.org:443\r\n" |
| 21732 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 21733 | mock_reads1.emplace_back( |
| 21734 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21735 | "Content-Length: 0\r\n" |
| 21736 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 21737 | // The client retries with credentials, and the request finally succeeds. |
| 21738 | mock_writes1.emplace_back( |
| 21739 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21740 | "Host: www.example.org:443\r\n" |
| 21741 | "Proxy-Connection: keep-alive\r\n" |
| 21742 | // Authenticate as proxyuser:proxypass. |
| 21743 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21744 | mock_reads1.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21745 | // The origin requests client certificates. |
| 21746 | SSLSocketDataProvider ssl_origin1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21747 | ssl_origin1.cert_request_info = cert_request_info_origin.get(); |
| 21748 | StaticSocketDataProvider data1(mock_reads1, mock_writes1); |
| 21749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 21751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 21752 | |
| 21753 | // The client responds to the origin client certificate request on a new |
| 21754 | // connection. |
| 21755 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21756 | std::vector<MockWrite> mock_writes2; |
| 21757 | std::vector<MockRead> mock_reads2; |
| 21758 | mock_writes2.emplace_back( |
| 21759 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21760 | "Host: www.example.org:443\r\n" |
| 21761 | "Proxy-Connection: keep-alive\r\n" |
| 21762 | // Authenticate as proxyuser:proxypass. |
| 21763 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21764 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21765 | SSLSocketDataProvider ssl_origin2(ASYNC, OK); |
| 21766 | ssl_origin2.expected_send_client_cert = true; |
| 21767 | ssl_origin2.expected_client_cert = identity_origin->certificate(); |
| 21768 | // The client sends the origin HTTP request, which succeeds. |
| 21769 | mock_writes2.emplace_back( |
| 21770 | "GET / HTTP/1.1\r\n" |
| 21771 | "Host: www.example.org\r\n" |
| 21772 | "Connection: keep-alive\r\n\r\n"); |
| 21773 | mock_reads2.emplace_back( |
| 21774 | "HTTP/1.1 200 OK\r\n" |
| 21775 | "Content-Length: 0\r\n\r\n"); |
| 21776 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 21777 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 21779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 21780 | |
| 21781 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21782 | |
| 21783 | // Start the request. |
| 21784 | TestCompletionCallback callback; |
| 21785 | auto trans = |
| 21786 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21787 | int rv = callback.GetResult( |
| 21788 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 21789 | |
| 21790 | // Handle the proxy HTTP auth challenge. |
| 21791 | ASSERT_THAT(rv, IsOk()); |
| 21792 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 21793 | EXPECT_TRUE( |
| 21794 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21795 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21796 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 21797 | callback.callback())); |
| 21798 | |
| 21799 | // Handle the origin client certificate challenge. |
| 21800 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21801 | SSLCertRequestInfo* cert_request_info = |
| 21802 | trans->GetResponseInfo()->cert_request_info.get(); |
| 21803 | ASSERT_TRUE(cert_request_info); |
| 21804 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 21805 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21806 | cert_request_info_origin->host_and_port); |
| 21807 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21808 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 21809 | callback.callback())); |
| 21810 | |
| 21811 | // The request completes. |
| 21812 | ASSERT_THAT(rv, IsOk()); |
| 21813 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21814 | } |
| 21815 | |
David Benjamin | 6e673a8 | 2019-04-30 22:52:58 | [diff] [blame] | 21816 | // Test that socket reuse works with client certificates. |
| 21817 | TEST_F(HttpNetworkTransactionTest, ClientCertSocketReuse) { |
| 21818 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21819 | cert_request_info->host_and_port = HostPortPair("www.example.org", 443); |
| 21820 | |
| 21821 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 21822 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21823 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21824 | ASSERT_TRUE(identity); |
| 21825 | |
| 21826 | HttpRequestInfo request1; |
| 21827 | request1.method = "GET"; |
| 21828 | request1.url = GURL("https://www.example.org/a"); |
| 21829 | request1.traffic_annotation = |
| 21830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21831 | |
| 21832 | HttpRequestInfo request2; |
| 21833 | request2.method = "GET"; |
| 21834 | request2.url = GURL("https://www.example.org/b"); |
| 21835 | request2.traffic_annotation = |
| 21836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21837 | |
| 21838 | // The first connection results in a client certificate request. |
| 21839 | StaticSocketDataProvider data1; |
| 21840 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21841 | SSLSocketDataProvider ssl1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21842 | ssl1.cert_request_info = cert_request_info.get(); |
| 21843 | ssl1.expected_send_client_cert = false; |
| 21844 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 21845 | |
| 21846 | // The second connection succeeds and is usable for both requests. |
| 21847 | MockWrite mock_writes[] = { |
| 21848 | MockWrite("GET /a HTTP/1.1\r\n" |
| 21849 | "Host: www.example.org\r\n" |
| 21850 | "Connection: keep-alive\r\n\r\n"), |
| 21851 | MockWrite("GET /b HTTP/1.1\r\n" |
| 21852 | "Host: www.example.org\r\n" |
| 21853 | "Connection: keep-alive\r\n\r\n"), |
| 21854 | }; |
| 21855 | MockRead mock_reads[] = { |
| 21856 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21857 | "Content-Length: 0\r\n\r\n"), |
| 21858 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21859 | "Content-Length: 0\r\n\r\n"), |
| 21860 | }; |
| 21861 | StaticSocketDataProvider data2(mock_reads, mock_writes); |
| 21862 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21863 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 21864 | ssl2.expected_send_client_cert = true; |
| 21865 | ssl2.expected_client_cert = identity->certificate(); |
| 21866 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 21867 | |
| 21868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21869 | |
| 21870 | // Start the first request. It succeeds after providing client certificates. |
| 21871 | TestCompletionCallback callback; |
| 21872 | auto trans = |
| 21873 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21874 | ASSERT_THAT(callback.GetResult(trans->Start(&request1, callback.callback(), |
| 21875 | NetLogWithSource())), |
| 21876 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21877 | |
| 21878 | SSLCertRequestInfo* info = trans->GetResponseInfo()->cert_request_info.get(); |
| 21879 | ASSERT_TRUE(info); |
| 21880 | EXPECT_FALSE(info->is_proxy); |
| 21881 | EXPECT_EQ(info->host_and_port, cert_request_info->host_and_port); |
| 21882 | |
| 21883 | ASSERT_THAT(callback.GetResult(trans->RestartWithCertificate( |
| 21884 | identity->certificate(), identity->ssl_private_key(), |
| 21885 | callback.callback())), |
| 21886 | IsOk()); |
| 21887 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 21888 | |
| 21889 | // Make the second request. It completes without requesting client |
| 21890 | // certificates. |
| 21891 | trans = |
| 21892 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21893 | ASSERT_THAT(callback.GetResult(trans->Start(&request2, callback.callback(), |
| 21894 | NetLogWithSource())), |
| 21895 | IsOk()); |
| 21896 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 21897 | } |
| 21898 | |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 21899 | // Test for kPartitionConnectionsByNetworkIsolationKey. Runs 3 requests in |
| 21900 | // sequence with two different NetworkIsolationKeys, the first and last have the |
| 21901 | // same key, the second a different one. Checks that the requests are |
| 21902 | // partitioned across sockets as expected. |
| 21903 | TEST_F(HttpNetworkTransactionTest, NetworkIsolation) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21904 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21905 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21906 | NetworkIsolationKey network_isolation_key1(kOrigin1, kOrigin1); |
| 21907 | NetworkIsolationKey network_isolation_key2(kOrigin2, kOrigin2); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 21908 | |
| 21909 | for (bool partition_connections : {false, true}) { |
| 21910 | SCOPED_TRACE(partition_connections); |
| 21911 | |
| 21912 | base::test::ScopedFeatureList feature_list; |
| 21913 | if (partition_connections) { |
| 21914 | feature_list.InitAndEnableFeature( |
| 21915 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21916 | } else { |
| 21917 | feature_list.InitAndDisableFeature( |
| 21918 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21919 | } |
| 21920 | |
| 21921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21922 | |
| 21923 | // Reads and writes for the unpartitioned case, where only one socket is |
| 21924 | // used. |
| 21925 | |
| 21926 | const MockWrite kUnpartitionedWrites[] = { |
| 21927 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21928 | "Host: foo.test\r\n" |
| 21929 | "Connection: keep-alive\r\n\r\n"), |
| 21930 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21931 | "Host: foo.test\r\n" |
| 21932 | "Connection: keep-alive\r\n\r\n"), |
| 21933 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21934 | "Host: foo.test\r\n" |
| 21935 | "Connection: keep-alive\r\n\r\n"), |
| 21936 | }; |
| 21937 | |
| 21938 | const MockRead kUnpartitionedReads[] = { |
| 21939 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21940 | "Connection: keep-alive\r\n" |
| 21941 | "Content-Length: 1\r\n\r\n" |
| 21942 | "1"), |
| 21943 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21944 | "Connection: keep-alive\r\n" |
| 21945 | "Content-Length: 1\r\n\r\n" |
| 21946 | "2"), |
| 21947 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21948 | "Connection: keep-alive\r\n" |
| 21949 | "Content-Length: 1\r\n\r\n" |
| 21950 | "3"), |
| 21951 | }; |
| 21952 | |
| 21953 | StaticSocketDataProvider unpartitioned_data(kUnpartitionedReads, |
| 21954 | kUnpartitionedWrites); |
| 21955 | |
| 21956 | // Reads and writes for the partitioned case, where two sockets are used. |
| 21957 | |
| 21958 | const MockWrite kPartitionedWrites1[] = { |
| 21959 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21960 | "Host: foo.test\r\n" |
| 21961 | "Connection: keep-alive\r\n\r\n"), |
| 21962 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21963 | "Host: foo.test\r\n" |
| 21964 | "Connection: keep-alive\r\n\r\n"), |
| 21965 | }; |
| 21966 | |
| 21967 | const MockRead kPartitionedReads1[] = { |
| 21968 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21969 | "Connection: keep-alive\r\n" |
| 21970 | "Content-Length: 1\r\n\r\n" |
| 21971 | "1"), |
| 21972 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21973 | "Connection: keep-alive\r\n" |
| 21974 | "Content-Length: 1\r\n\r\n" |
| 21975 | "3"), |
| 21976 | }; |
| 21977 | |
| 21978 | const MockWrite kPartitionedWrites2[] = { |
| 21979 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21980 | "Host: foo.test\r\n" |
| 21981 | "Connection: keep-alive\r\n\r\n"), |
| 21982 | }; |
| 21983 | |
| 21984 | const MockRead kPartitionedReads2[] = { |
| 21985 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21986 | "Connection: keep-alive\r\n" |
| 21987 | "Content-Length: 1\r\n\r\n" |
| 21988 | "2"), |
| 21989 | }; |
| 21990 | |
| 21991 | StaticSocketDataProvider partitioned_data1(kPartitionedReads1, |
| 21992 | kPartitionedWrites1); |
| 21993 | StaticSocketDataProvider partitioned_data2(kPartitionedReads2, |
| 21994 | kPartitionedWrites2); |
| 21995 | |
| 21996 | if (partition_connections) { |
| 21997 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 21998 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 21999 | } else { |
| 22000 | session_deps_.socket_factory->AddSocketDataProvider(&unpartitioned_data); |
| 22001 | } |
| 22002 | |
| 22003 | TestCompletionCallback callback; |
| 22004 | HttpRequestInfo request1; |
| 22005 | request1.method = "GET"; |
| 22006 | request1.url = GURL("http://foo.test/1"); |
| 22007 | request1.traffic_annotation = |
| 22008 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22009 | request1.network_isolation_key = network_isolation_key1; |
| 22010 | auto trans1 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 22011 | session.get()); |
| 22012 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22013 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22014 | std::string response_data1; |
| 22015 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22016 | EXPECT_EQ("1", response_data1); |
| 22017 | trans1.reset(); |
| 22018 | |
| 22019 | HttpRequestInfo request2; |
| 22020 | request2.method = "GET"; |
| 22021 | request2.url = GURL("http://foo.test/2"); |
| 22022 | request2.traffic_annotation = |
| 22023 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22024 | request2.network_isolation_key = network_isolation_key2; |
| 22025 | auto trans2 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 22026 | session.get()); |
| 22027 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22028 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22029 | std::string response_data2; |
| 22030 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22031 | EXPECT_EQ("2", response_data2); |
| 22032 | trans2.reset(); |
| 22033 | |
| 22034 | HttpRequestInfo request3; |
| 22035 | request3.method = "GET"; |
| 22036 | request3.url = GURL("http://foo.test/3"); |
| 22037 | request3.traffic_annotation = |
| 22038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22039 | request3.network_isolation_key = network_isolation_key1; |
| 22040 | auto trans3 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 22041 | session.get()); |
| 22042 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22043 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22044 | std::string response_data3; |
| 22045 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22046 | EXPECT_EQ("3", response_data3); |
| 22047 | trans3.reset(); |
| 22048 | } |
| 22049 | } |
| 22050 | |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22051 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationH2) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 22052 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 22053 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 22054 | NetworkIsolationKey network_isolation_key1(kOrigin1, kOrigin1); |
| 22055 | NetworkIsolationKey network_isolation_key2(kOrigin2, kOrigin2); |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22056 | |
| 22057 | // Whether to use an H2 proxy. When false, uses HTTPS H2 requests without a |
| 22058 | // proxy, when true, uses HTTP requests over an H2 proxy. It's unnecessary to |
| 22059 | // test tunneled HTTPS over an H2 proxy, since that path sets up H2 sessions |
| 22060 | // the same way as the HTTP over H2 proxy case. |
| 22061 | for (bool use_proxy : {false, true}) { |
| 22062 | SCOPED_TRACE(use_proxy); |
| 22063 | if (use_proxy) { |
| 22064 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 22065 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22066 | "HTTPS proxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22067 | } else { |
| 22068 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 22069 | ConfiguredProxyResolutionService::CreateDirect(); |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22070 | } |
| 22071 | const char* url1 = nullptr; |
| 22072 | const char* url2 = nullptr; |
| 22073 | const char* url3 = nullptr; |
| 22074 | if (use_proxy) { |
| 22075 | url1 = "http://foo.test/1"; |
| 22076 | url2 = "http://foo.test/2"; |
| 22077 | url3 = "http://foo.test/3"; |
| 22078 | } else { |
| 22079 | url1 = "https://foo.test/1"; |
| 22080 | url2 = "https://foo.test/2"; |
| 22081 | url3 = "https://foo.test/3"; |
| 22082 | } |
| 22083 | |
| 22084 | for (bool partition_connections : {false, true}) { |
| 22085 | SCOPED_TRACE(partition_connections); |
| 22086 | |
| 22087 | base::test::ScopedFeatureList feature_list; |
| 22088 | if (partition_connections) { |
| 22089 | feature_list.InitAndEnableFeature( |
| 22090 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22091 | } else { |
| 22092 | feature_list.InitAndDisableFeature( |
| 22093 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22094 | } |
| 22095 | |
| 22096 | std::unique_ptr<HttpNetworkSession> session( |
| 22097 | CreateSession(&session_deps_)); |
| 22098 | |
| 22099 | // Reads and writes for the unpartitioned case, where only one socket is |
| 22100 | // used. |
| 22101 | |
| 22102 | SpdyTestUtil spdy_util; |
| 22103 | spdy::SpdySerializedFrame unpartitioned_req1( |
| 22104 | spdy_util.ConstructSpdyGet(url1, 1, LOWEST)); |
| 22105 | spdy::SpdySerializedFrame unpartitioned_response1( |
| 22106 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 22107 | spdy::SpdySerializedFrame unpartitioned_body1( |
| 22108 | spdy_util.ConstructSpdyDataFrame(1, "1", true)); |
| 22109 | spdy_util.UpdateWithStreamDestruction(1); |
| 22110 | |
| 22111 | spdy::SpdySerializedFrame unpartitioned_req2( |
| 22112 | spdy_util.ConstructSpdyGet(url2, 3, LOWEST)); |
| 22113 | spdy::SpdySerializedFrame unpartitioned_response2( |
| 22114 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 22115 | spdy::SpdySerializedFrame unpartitioned_body2( |
| 22116 | spdy_util.ConstructSpdyDataFrame(3, "2", true)); |
| 22117 | spdy_util.UpdateWithStreamDestruction(3); |
| 22118 | |
| 22119 | spdy::SpdySerializedFrame unpartitioned_req3( |
| 22120 | spdy_util.ConstructSpdyGet(url3, 5, LOWEST)); |
| 22121 | spdy::SpdySerializedFrame unpartitioned_response3( |
| 22122 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 5)); |
| 22123 | spdy::SpdySerializedFrame unpartitioned_body3( |
| 22124 | spdy_util.ConstructSpdyDataFrame(5, "3", true)); |
| 22125 | |
| 22126 | const MockWrite kUnpartitionedWrites[] = { |
| 22127 | CreateMockWrite(unpartitioned_req1, 0), |
| 22128 | CreateMockWrite(unpartitioned_req2, 3), |
| 22129 | CreateMockWrite(unpartitioned_req3, 6), |
| 22130 | }; |
| 22131 | |
| 22132 | const MockRead kUnpartitionedReads[] = { |
| 22133 | CreateMockRead(unpartitioned_response1, 1), |
| 22134 | CreateMockRead(unpartitioned_body1, 2), |
| 22135 | CreateMockRead(unpartitioned_response2, 4), |
| 22136 | CreateMockRead(unpartitioned_body2, 5), |
| 22137 | CreateMockRead(unpartitioned_response3, 7), |
| 22138 | CreateMockRead(unpartitioned_body3, 8), |
| 22139 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 9), |
| 22140 | }; |
| 22141 | |
| 22142 | SequencedSocketData unpartitioned_data(kUnpartitionedReads, |
| 22143 | kUnpartitionedWrites); |
| 22144 | |
| 22145 | // Reads and writes for the partitioned case, where two sockets are used. |
| 22146 | |
| 22147 | SpdyTestUtil spdy_util2; |
| 22148 | spdy::SpdySerializedFrame partitioned_req1( |
| 22149 | spdy_util2.ConstructSpdyGet(url1, 1, LOWEST)); |
| 22150 | spdy::SpdySerializedFrame partitioned_response1( |
| 22151 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 22152 | spdy::SpdySerializedFrame partitioned_body1( |
| 22153 | spdy_util2.ConstructSpdyDataFrame(1, "1", true)); |
| 22154 | spdy_util2.UpdateWithStreamDestruction(1); |
| 22155 | |
| 22156 | spdy::SpdySerializedFrame partitioned_req3( |
| 22157 | spdy_util2.ConstructSpdyGet(url3, 3, LOWEST)); |
| 22158 | spdy::SpdySerializedFrame partitioned_response3( |
| 22159 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 22160 | spdy::SpdySerializedFrame partitioned_body3( |
| 22161 | spdy_util2.ConstructSpdyDataFrame(3, "3", true)); |
| 22162 | |
| 22163 | const MockWrite kPartitionedWrites1[] = { |
| 22164 | CreateMockWrite(partitioned_req1, 0), |
| 22165 | CreateMockWrite(partitioned_req3, 3), |
| 22166 | }; |
| 22167 | |
| 22168 | const MockRead kPartitionedReads1[] = { |
| 22169 | CreateMockRead(partitioned_response1, 1), |
| 22170 | CreateMockRead(partitioned_body1, 2), |
| 22171 | CreateMockRead(partitioned_response3, 4), |
| 22172 | CreateMockRead(partitioned_body3, 5), |
| 22173 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
| 22174 | }; |
| 22175 | |
| 22176 | SpdyTestUtil spdy_util3; |
| 22177 | spdy::SpdySerializedFrame partitioned_req2( |
| 22178 | spdy_util3.ConstructSpdyGet(url2, 1, LOWEST)); |
| 22179 | spdy::SpdySerializedFrame partitioned_response2( |
| 22180 | spdy_util3.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 22181 | spdy::SpdySerializedFrame partitioned_body2( |
| 22182 | spdy_util3.ConstructSpdyDataFrame(1, "2", true)); |
| 22183 | |
| 22184 | const MockWrite kPartitionedWrites2[] = { |
| 22185 | CreateMockWrite(partitioned_req2, 0), |
| 22186 | }; |
| 22187 | |
| 22188 | const MockRead kPartitionedReads2[] = { |
| 22189 | CreateMockRead(partitioned_response2, 1), |
| 22190 | CreateMockRead(partitioned_body2, 2), |
| 22191 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
| 22192 | }; |
| 22193 | |
| 22194 | SequencedSocketData partitioned_data1(kPartitionedReads1, |
| 22195 | kPartitionedWrites1); |
| 22196 | SequencedSocketData partitioned_data2(kPartitionedReads2, |
| 22197 | kPartitionedWrites2); |
| 22198 | |
| 22199 | // No need to segment SSLDataProviders by whether or not partitioning is |
| 22200 | // enabled. |
| 22201 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 22202 | ssl_data1.next_proto = kProtoHTTP2; |
| 22203 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 22204 | ssl_data2.next_proto = kProtoHTTP2; |
| 22205 | |
| 22206 | if (partition_connections) { |
| 22207 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 22208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 22209 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 22210 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 22211 | } else { |
| 22212 | session_deps_.socket_factory->AddSocketDataProvider( |
| 22213 | &unpartitioned_data); |
| 22214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 22215 | } |
| 22216 | |
| 22217 | TestCompletionCallback callback; |
| 22218 | HttpRequestInfo request1; |
| 22219 | request1.method = "GET"; |
| 22220 | request1.url = GURL(url1); |
| 22221 | request1.traffic_annotation = |
| 22222 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22223 | request1.network_isolation_key = network_isolation_key1; |
| 22224 | auto trans1 = |
| 22225 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 22226 | int rv = |
| 22227 | trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22228 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22229 | std::string response_data1; |
| 22230 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22231 | EXPECT_EQ("1", response_data1); |
| 22232 | trans1.reset(); |
| 22233 | |
| 22234 | HttpRequestInfo request2; |
| 22235 | request2.method = "GET"; |
| 22236 | request2.url = GURL(url2); |
| 22237 | request2.traffic_annotation = |
| 22238 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22239 | request2.network_isolation_key = network_isolation_key2; |
| 22240 | auto trans2 = |
| 22241 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 22242 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22243 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22244 | std::string response_data2; |
| 22245 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22246 | EXPECT_EQ("2", response_data2); |
| 22247 | trans2.reset(); |
| 22248 | |
| 22249 | HttpRequestInfo request3; |
| 22250 | request3.method = "GET"; |
| 22251 | request3.url = GURL(url3); |
| 22252 | request3.traffic_annotation = |
| 22253 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22254 | request3.network_isolation_key = network_isolation_key1; |
| 22255 | auto trans3 = |
| 22256 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 22257 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22258 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22259 | std::string response_data3; |
| 22260 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22261 | EXPECT_EQ("3", response_data3); |
| 22262 | trans3.reset(); |
| 22263 | } |
| 22264 | } |
| 22265 | } |
| 22266 | |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 22267 | // Preconnect two sockets with different NetworkIsolationKeys when |
| 22268 | // features::kPartitionConnectionsByNetworkIsolationKey is enabled. Then issue a |
| 22269 | // request and make sure the correct socket is used. Loops three times, |
| 22270 | // expecting to use the first preconnect, second preconnect, and neither. |
| 22271 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationPreconnect) { |
| 22272 | base::test::ScopedFeatureList feature_list; |
| 22273 | feature_list.InitAndEnableFeature( |
| 22274 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22275 | |
| 22276 | enum class TestCase { |
| 22277 | kUseFirstPreconnect, |
| 22278 | kUseSecondPreconnect, |
| 22279 | kDontUsePreconnect, |
| 22280 | }; |
| 22281 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 22282 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 22283 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 22284 | const auto kOrigin3 = url::Origin::Create(GURL("http://origin3/")); |
| 22285 | NetworkIsolationKey preconnect1_isolation_key(kOrigin1, kOrigin1); |
| 22286 | NetworkIsolationKey preconnect2_isolation_key(kOrigin2, kOrigin2); |
| 22287 | NetworkIsolationKey not_preconnected_isolation_key(kOrigin3, kOrigin3); |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 22288 | |
| 22289 | // Test that only preconnects with |
| 22290 | for (TestCase test_case : |
| 22291 | {TestCase::kUseFirstPreconnect, TestCase::kUseSecondPreconnect, |
| 22292 | TestCase::kDontUsePreconnect}) { |
| 22293 | SpdySessionDependencies session_deps; |
| 22294 | // Make DNS lookups completely synchronously, so preconnects complete |
| 22295 | // immediately. |
| 22296 | session_deps.host_resolver->set_synchronous_mode(true); |
| 22297 | |
| 22298 | const MockWrite kMockWrites[] = { |
| 22299 | MockWrite(ASYNC, 0, |
| 22300 | "GET / HTTP/1.1\r\n" |
| 22301 | "Host: www.foo.com\r\n" |
| 22302 | "Connection: keep-alive\r\n\r\n"), |
| 22303 | }; |
| 22304 | |
| 22305 | const MockRead kMockReads[] = { |
| 22306 | MockRead(ASYNC, 1, |
| 22307 | "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n" |
| 22308 | "hello"), |
| 22309 | }; |
| 22310 | |
| 22311 | // Used for the socket that will actually be used, which may or may not be |
| 22312 | // one of the preconnects |
| 22313 | SequencedSocketData used_socket_data(MockConnect(SYNCHRONOUS, OK), |
| 22314 | kMockReads, kMockWrites); |
| 22315 | |
| 22316 | // Used for the preconnects that won't actually be used. |
| 22317 | SequencedSocketData preconnect1_data(MockConnect(SYNCHRONOUS, OK), |
| 22318 | base::span<const MockRead>(), |
| 22319 | base::span<const MockWrite>()); |
| 22320 | SequencedSocketData preconnect2_data(MockConnect(SYNCHRONOUS, OK), |
| 22321 | base::span<const MockRead>(), |
| 22322 | base::span<const MockWrite>()); |
| 22323 | |
| 22324 | NetworkIsolationKey network_isolation_key_for_request; |
| 22325 | |
| 22326 | switch (test_case) { |
| 22327 | case TestCase::kUseFirstPreconnect: |
| 22328 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 22329 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 22330 | network_isolation_key_for_request = preconnect1_isolation_key; |
| 22331 | break; |
| 22332 | case TestCase::kUseSecondPreconnect: |
| 22333 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 22334 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 22335 | network_isolation_key_for_request = preconnect2_isolation_key; |
| 22336 | break; |
| 22337 | case TestCase::kDontUsePreconnect: |
| 22338 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 22339 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 22340 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 22341 | network_isolation_key_for_request = not_preconnected_isolation_key; |
| 22342 | break; |
| 22343 | } |
| 22344 | |
| 22345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 22346 | |
| 22347 | // Preconnect sockets. |
| 22348 | HttpRequestInfo request; |
| 22349 | request.method = "GET"; |
| 22350 | request.url = GURL("http://www.foo.com/"); |
| 22351 | request.traffic_annotation = |
| 22352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22353 | |
| 22354 | request.network_isolation_key = preconnect1_isolation_key; |
| 22355 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 22356 | |
| 22357 | request.network_isolation_key = preconnect2_isolation_key; |
| 22358 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 22359 | |
| 22360 | request.network_isolation_key = network_isolation_key_for_request; |
| 22361 | |
| 22362 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 22363 | |
| 22364 | // Make the request. |
| 22365 | TestCompletionCallback callback; |
| 22366 | |
| 22367 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 22368 | |
| 22369 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 22370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22371 | |
| 22372 | rv = callback.WaitForResult(); |
| 22373 | EXPECT_THAT(rv, IsOk()); |
| 22374 | |
| 22375 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 22376 | ASSERT_TRUE(response); |
| 22377 | ASSERT_TRUE(response->headers); |
| 22378 | EXPECT_EQ(200, response->headers->response_code()); |
| 22379 | |
| 22380 | std::string response_data; |
| 22381 | rv = ReadTransaction(&trans, &response_data); |
| 22382 | EXPECT_THAT(rv, IsOk()); |
| 22383 | EXPECT_EQ("hello", response_data); |
| 22384 | |
| 22385 | if (test_case != TestCase::kDontUsePreconnect) { |
| 22386 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 22387 | } else { |
| 22388 | EXPECT_EQ(3, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 22389 | } |
| 22390 | } |
| 22391 | } |
| 22392 | |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22393 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 22394 | // cache is isolated. |
| 22395 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSL) { |
| 22396 | base::test::ScopedFeatureList feature_list; |
| 22397 | feature_list.InitWithFeatures( |
| 22398 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 22399 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 22400 | {}); |
| 22401 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 22402 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 22403 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 22404 | const NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 22405 | const NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22406 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22407 | |
| 22408 | // The server always sends Connection: close, so each request goes over a |
| 22409 | // distinct socket. |
| 22410 | |
| 22411 | const MockWrite kWrites1[] = { |
| 22412 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22413 | "Host: foo.test\r\n" |
| 22414 | "Connection: keep-alive\r\n\r\n")}; |
| 22415 | |
| 22416 | const MockRead kReads1[] = { |
| 22417 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22418 | "Connection: close\r\n" |
| 22419 | "Content-Length: 1\r\n\r\n" |
| 22420 | "1")}; |
| 22421 | |
| 22422 | const MockWrite kWrites2[] = { |
| 22423 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 22424 | "Host: foo.test\r\n" |
| 22425 | "Connection: keep-alive\r\n\r\n")}; |
| 22426 | |
| 22427 | const MockRead kReads2[] = { |
| 22428 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22429 | "Connection: close\r\n" |
| 22430 | "Content-Length: 1\r\n\r\n" |
| 22431 | "2")}; |
| 22432 | |
| 22433 | const MockWrite kWrites3[] = { |
| 22434 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 22435 | "Host: foo.test\r\n" |
| 22436 | "Connection: keep-alive\r\n\r\n")}; |
| 22437 | |
| 22438 | const MockRead kReads3[] = { |
| 22439 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22440 | "Connection: close\r\n" |
| 22441 | "Content-Length: 1\r\n\r\n" |
| 22442 | "3")}; |
| 22443 | |
| 22444 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 22445 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 22446 | StaticSocketDataProvider data3(kReads3, kWrites3); |
| 22447 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22448 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22449 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 22450 | |
| 22451 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 22452 | ssl_data1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22453 | ssl_data1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22454 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 22455 | ssl_data2.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22456 | ssl_data2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 22457 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
| 22458 | ssl_data3.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22459 | ssl_data3.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 22461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 22462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
| 22463 | |
| 22464 | TestCompletionCallback callback; |
| 22465 | HttpRequestInfo request1; |
| 22466 | request1.method = "GET"; |
| 22467 | request1.url = GURL("https://foo.test/1"); |
| 22468 | request1.traffic_annotation = |
| 22469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22470 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 22471 | auto trans1 = |
| 22472 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22473 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22474 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22475 | std::string response_data1; |
| 22476 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22477 | EXPECT_EQ("1", response_data1); |
| 22478 | trans1.reset(); |
| 22479 | |
| 22480 | HttpRequestInfo request2; |
| 22481 | request2.method = "GET"; |
| 22482 | request2.url = GURL("https://foo.test/2"); |
| 22483 | request2.traffic_annotation = |
| 22484 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22485 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 22486 | auto trans2 = |
| 22487 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22488 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22489 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22490 | std::string response_data2; |
| 22491 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22492 | EXPECT_EQ("2", response_data2); |
| 22493 | trans2.reset(); |
| 22494 | |
| 22495 | HttpRequestInfo request3; |
| 22496 | request3.method = "GET"; |
| 22497 | request3.url = GURL("https://foo.test/3"); |
| 22498 | request3.traffic_annotation = |
| 22499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22500 | request3.network_isolation_key = kNetworkIsolationKey1; |
| 22501 | auto trans3 = |
| 22502 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22503 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22504 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22505 | std::string response_data3; |
| 22506 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22507 | EXPECT_EQ("3", response_data3); |
| 22508 | trans3.reset(); |
| 22509 | } |
| 22510 | |
| 22511 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 22512 | // cache is isolated, for both origins and proxies. |
| 22513 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSLProxy) { |
| 22514 | base::test::ScopedFeatureList feature_list; |
| 22515 | feature_list.InitWithFeatures( |
| 22516 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 22517 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 22518 | {}); |
| 22519 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 22520 | session_deps_.proxy_resolution_service = |
| 22521 | ConfiguredProxyResolutionService::CreateFixed( |
| 22522 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22523 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 22524 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 22525 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 22526 | const NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 22527 | const NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22528 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22529 | |
| 22530 | // Make both a tunneled and non-tunneled request. |
| 22531 | HttpRequestInfo request1; |
| 22532 | request1.method = "GET"; |
| 22533 | request1.url = GURL("https://foo.test/1"); |
| 22534 | request1.traffic_annotation = |
| 22535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22536 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 22537 | |
| 22538 | HttpRequestInfo request2; |
| 22539 | request2.method = "GET"; |
| 22540 | request2.url = GURL("http://foo.test/2"); |
| 22541 | request2.traffic_annotation = |
| 22542 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22543 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 22544 | |
| 22545 | const MockWrite kWrites1[] = { |
| 22546 | MockWrite("CONNECT foo.test:443 HTTP/1.1\r\n" |
| 22547 | "Host: foo.test:443\r\n" |
| 22548 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 22549 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22550 | "Host: foo.test\r\n" |
| 22551 | "Connection: keep-alive\r\n\r\n")}; |
| 22552 | |
| 22553 | const MockRead kReads1[] = { |
| 22554 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 22555 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22556 | "Connection: close\r\n" |
| 22557 | "Content-Length: 1\r\n\r\n" |
| 22558 | "1")}; |
| 22559 | |
| 22560 | const MockWrite kWrites2[] = { |
| 22561 | MockWrite("GET http://foo.test/2 HTTP/1.1\r\n" |
| 22562 | "Host: foo.test\r\n" |
| 22563 | "Proxy-Connection: keep-alive\r\n\r\n")}; |
| 22564 | |
| 22565 | const MockRead kReads2[] = { |
| 22566 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22567 | "Connection: close\r\n" |
| 22568 | "Content-Length: 1\r\n\r\n" |
| 22569 | "2")}; |
| 22570 | |
| 22571 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 22572 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 22573 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22574 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22575 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22576 | |
| 22577 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 22578 | ssl_proxy1.expected_host_and_port = HostPortPair("myproxy", 70); |
| 22579 | ssl_proxy1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22580 | SSLSocketDataProvider ssl_origin1(ASYNC, OK); |
| 22581 | ssl_origin1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22582 | ssl_origin1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22583 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 22584 | ssl_proxy2.expected_host_and_port = HostPortPair("myproxy", 70); |
| 22585 | ssl_proxy2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 22586 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 22587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 22588 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 22589 | |
| 22590 | TestCompletionCallback callback; |
| 22591 | auto trans1 = |
| 22592 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22593 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22594 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22595 | std::string response_data1; |
| 22596 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22597 | EXPECT_EQ("1", response_data1); |
| 22598 | trans1.reset(); |
| 22599 | |
| 22600 | auto trans2 = |
| 22601 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22602 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22603 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22604 | std::string response_data2; |
| 22605 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22606 | EXPECT_EQ("2", response_data2); |
| 22607 | trans2.reset(); |
| 22608 | } |
| 22609 | |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22610 | // Test that SSLConfig changes from SSLConfigService are picked up even when |
| 22611 | // there are live sockets. |
| 22612 | TEST_F(HttpNetworkTransactionTest, SSLConfigChanged) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22613 | SSLContextConfig ssl_context_config; |
| 22614 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22615 | auto ssl_config_service = |
| 22616 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22617 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 22618 | |
| 22619 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 22620 | |
| 22621 | // Make three requests. Between the second and third, the SSL config will |
| 22622 | // change. |
| 22623 | HttpRequestInfo request1; |
| 22624 | request1.method = "GET"; |
| 22625 | request1.url = GURL("https://foo.test/1"); |
| 22626 | request1.traffic_annotation = |
| 22627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22628 | |
| 22629 | HttpRequestInfo request2; |
| 22630 | request2.method = "GET"; |
| 22631 | request2.url = GURL("https://foo.test/2"); |
| 22632 | request2.traffic_annotation = |
| 22633 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22634 | |
| 22635 | HttpRequestInfo request3; |
| 22636 | request3.method = "GET"; |
| 22637 | request3.url = GURL("https://foo.test/3"); |
| 22638 | request3.traffic_annotation = |
| 22639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22640 | |
| 22641 | const MockWrite kWrites1[] = { |
| 22642 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22643 | "Host: foo.test\r\n" |
| 22644 | "Connection: keep-alive\r\n\r\n"), |
| 22645 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 22646 | "Host: foo.test\r\n" |
| 22647 | "Connection: keep-alive\r\n\r\n"), |
| 22648 | }; |
| 22649 | |
| 22650 | const MockRead kReads1[] = { |
| 22651 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22652 | "Connection: keep-alive\r\n" |
| 22653 | "Content-Length: 1\r\n\r\n" |
| 22654 | "1"), |
| 22655 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22656 | "Connection: keep-alive\r\n" |
| 22657 | "Content-Length: 1\r\n\r\n" |
| 22658 | "2"), |
| 22659 | }; |
| 22660 | |
| 22661 | // The third request goes on a different socket because the SSL config has |
| 22662 | // changed. |
| 22663 | const MockWrite kWrites2[] = { |
| 22664 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 22665 | "Host: foo.test\r\n" |
| 22666 | "Connection: keep-alive\r\n\r\n")}; |
| 22667 | |
| 22668 | const MockRead kReads2[] = { |
| 22669 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22670 | "Connection: keep-alive\r\n" |
| 22671 | "Content-Length: 1\r\n\r\n" |
| 22672 | "3")}; |
| 22673 | |
| 22674 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 22675 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 22676 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22677 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22678 | |
| 22679 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 22680 | ssl1.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22681 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 22682 | ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 22683 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 22684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 22685 | |
| 22686 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22687 | |
| 22688 | TestCompletionCallback callback; |
| 22689 | auto trans1 = |
| 22690 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22691 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22692 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22693 | std::string response_data1; |
| 22694 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22695 | EXPECT_EQ("1", response_data1); |
| 22696 | trans1.reset(); |
| 22697 | |
| 22698 | auto trans2 = |
| 22699 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22700 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22701 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22702 | std::string response_data2; |
| 22703 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22704 | EXPECT_EQ("2", response_data2); |
| 22705 | trans2.reset(); |
| 22706 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22707 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 22708 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22709 | |
| 22710 | auto trans3 = |
| 22711 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22712 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22713 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22714 | std::string response_data3; |
| 22715 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22716 | EXPECT_EQ("3", response_data3); |
| 22717 | trans3.reset(); |
| 22718 | } |
| 22719 | |
| 22720 | TEST_F(HttpNetworkTransactionTest, SSLConfigChangedPendingConnect) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22721 | SSLContextConfig ssl_context_config; |
| 22722 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22723 | auto ssl_config_service = |
| 22724 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22725 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 22726 | |
| 22727 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 22728 | |
| 22729 | HttpRequestInfo request; |
| 22730 | request.method = "GET"; |
| 22731 | request.url = GURL("https://foo.test/1"); |
| 22732 | request.traffic_annotation = |
| 22733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22734 | |
| 22735 | // Make a socket which never connects. |
| 22736 | StaticSocketDataProvider data({}, {}); |
| 22737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 22738 | SSLSocketDataProvider ssl_data(SYNCHRONOUS, ERR_IO_PENDING); |
| 22739 | ssl_data.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
| 22741 | |
| 22742 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22743 | |
| 22744 | TestCompletionCallback callback; |
| 22745 | auto trans = |
| 22746 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22747 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 22748 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22749 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22750 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 22751 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22752 | |
| 22753 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NETWORK_CHANGED)); |
| 22754 | } |
| 22755 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 22756 | // Test that HttpNetworkTransaction correctly handles existing sockets when the |
| 22757 | // server requests a client certificate post-handshake (via a TLS |
| 22758 | // renegotiation). This is a regression test for https://crbug.com/829184. |
| 22759 | TEST_F(HttpNetworkTransactionTest, PostHandshakeClientCertWithSockets) { |
| 22760 | const MutableNetworkTrafficAnnotationTag kTrafficAnnotation( |
| 22761 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22762 | |
| 22763 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 22764 | cert_request_info->host_and_port = HostPortPair("foo.test", 443); |
| 22765 | |
| 22766 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 22767 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 22768 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 22769 | ASSERT_TRUE(identity); |
| 22770 | |
| 22771 | // This test will make several requests so that, when the client certificate |
| 22772 | // request comes in, we have a socket in use, an idle socket, and a socket for |
| 22773 | // an unrelated host. |
| 22774 | // |
| 22775 | // First, two long-lived requests which do not complete until after the client |
| 22776 | // certificate request. This arranges for sockets to be in use during the |
| 22777 | // request. They should not be interrupted. |
| 22778 | HttpRequestInfo request_long_lived; |
| 22779 | request_long_lived.method = "GET"; |
| 22780 | request_long_lived.url = GURL("https://foo.test/long-lived"); |
| 22781 | request_long_lived.traffic_annotation = kTrafficAnnotation; |
| 22782 | |
| 22783 | HttpRequestInfo request_long_lived_bar; |
| 22784 | request_long_lived_bar.method = "GET"; |
| 22785 | request_long_lived_bar.url = GURL("https://bar.test/long-lived"); |
| 22786 | request_long_lived_bar.traffic_annotation = kTrafficAnnotation; |
| 22787 | |
| 22788 | // Next, make a request that needs client certificates. |
| 22789 | HttpRequestInfo request_auth; |
| 22790 | request_auth.method = "GET"; |
| 22791 | request_auth.url = GURL("https://foo.test/auth"); |
| 22792 | request_auth.traffic_annotation = kTrafficAnnotation; |
| 22793 | |
| 22794 | // Before responding to the challenge, make a request to an unauthenticated |
| 22795 | // endpoint. This will result in an idle socket when the client certificate |
| 22796 | // challenge is resolved. |
| 22797 | HttpRequestInfo request_unauth; |
| 22798 | request_unauth.method = "GET"; |
| 22799 | request_unauth.url = GURL("https://foo.test/unauth"); |
| 22800 | request_unauth.traffic_annotation = kTrafficAnnotation; |
| 22801 | |
| 22802 | // After all the preceding requests complete, end with two additional requests |
| 22803 | // to ensure pre-authentication foo.test sockets are not used and bar.test |
| 22804 | // sockets are unaffected. |
| 22805 | HttpRequestInfo request_post_auth; |
| 22806 | request_post_auth.method = "GET"; |
| 22807 | request_post_auth.url = GURL("https://foo.test/post-auth"); |
| 22808 | request_post_auth.traffic_annotation = kTrafficAnnotation; |
| 22809 | |
| 22810 | HttpRequestInfo request_post_auth_bar; |
| 22811 | request_post_auth_bar.method = "GET"; |
| 22812 | request_post_auth_bar.url = GURL("https://bar.test/post-auth"); |
| 22813 | request_post_auth_bar.traffic_annotation = kTrafficAnnotation; |
| 22814 | |
| 22815 | // The sockets for /long-lived and /unauth complete their request but are |
| 22816 | // not allocated for /post-auth or /retry because SSL state has since changed. |
| 22817 | const MockWrite kLongLivedWrites[] = { |
| 22818 | MockWrite(ASYNC, 0, |
| 22819 | "GET /long-lived HTTP/1.1\r\n" |
| 22820 | "Host: foo.test\r\n" |
| 22821 | "Connection: keep-alive\r\n\r\n"), |
| 22822 | }; |
| 22823 | const MockRead kLongLivedReads[] = { |
| 22824 | // Pause so /long-lived completes after the client presents client |
| 22825 | // certificates. |
| 22826 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 22827 | MockRead(ASYNC, 2, |
| 22828 | "HTTP/1.1 200 OK\r\n" |
| 22829 | "Connection: keep-alive\r\n" |
| 22830 | "Content-Length: 10\r\n\r\n" |
| 22831 | "long-lived"), |
| 22832 | }; |
| 22833 | SequencedSocketData data_long_lived(kLongLivedReads, kLongLivedWrites); |
| 22834 | SSLSocketDataProvider ssl_long_lived(ASYNC, OK); |
| 22835 | session_deps_.socket_factory->AddSocketDataProvider(&data_long_lived); |
| 22836 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_long_lived); |
| 22837 | |
| 22838 | // Requests for bar.test should be unaffected by foo.test and get allocated |
| 22839 | // a single socket. |
| 22840 | const MockWrite kBarWrites[] = { |
| 22841 | MockWrite(ASYNC, 0, |
| 22842 | "GET /long-lived HTTP/1.1\r\n" |
| 22843 | "Host: bar.test\r\n" |
| 22844 | "Connection: keep-alive\r\n\r\n"), |
| 22845 | MockWrite(ASYNC, 3, |
| 22846 | "GET /post-auth HTTP/1.1\r\n" |
| 22847 | "Host: bar.test\r\n" |
| 22848 | "Connection: keep-alive\r\n\r\n"), |
| 22849 | }; |
| 22850 | const MockRead kBarReads[] = { |
| 22851 | // Pause on /long-lived so it completes after foo.test's authentication. |
| 22852 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 22853 | MockRead(ASYNC, 2, |
| 22854 | "HTTP/1.1 200 OK\r\n" |
| 22855 | "Connection: keep-alive\r\n" |
| 22856 | "Content-Length: 10\r\n\r\n" |
| 22857 | "long-lived"), |
| 22858 | MockRead(ASYNC, 4, |
| 22859 | "HTTP/1.1 200 OK\r\n" |
| 22860 | "Connection: keep-alive\r\n" |
| 22861 | "Content-Length: 9\r\n\r\n" |
| 22862 | "post-auth"), |
| 22863 | }; |
| 22864 | SequencedSocketData data_bar(kBarReads, kBarWrites); |
| 22865 | SSLSocketDataProvider ssl_bar(ASYNC, OK); |
| 22866 | session_deps_.socket_factory->AddSocketDataProvider(&data_bar); |
| 22867 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bar); |
| 22868 | |
| 22869 | // Requesting /auth results in a post-handshake client certificate challenge. |
| 22870 | const MockWrite kAuthWrites[] = { |
| 22871 | MockWrite(ASYNC, 0, |
| 22872 | "GET /auth HTTP/1.1\r\n" |
| 22873 | "Host: foo.test\r\n" |
| 22874 | "Connection: keep-alive\r\n\r\n"), |
| 22875 | }; |
| 22876 | const MockRead kAuthReads[] = { |
| 22877 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED, 1), |
| 22878 | }; |
| 22879 | SequencedSocketData data_auth(kAuthReads, kAuthWrites); |
| 22880 | SSLSocketDataProvider ssl_auth(ASYNC, OK); |
| 22881 | ssl_auth.cert_request_info = cert_request_info.get(); |
| 22882 | session_deps_.socket_factory->AddSocketDataProvider(&data_auth); |
| 22883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_auth); |
| 22884 | |
| 22885 | // Requesting /unauth completes. |
| 22886 | const MockWrite kUnauthWrites[] = { |
| 22887 | MockWrite(ASYNC, 0, |
| 22888 | "GET /unauth HTTP/1.1\r\n" |
| 22889 | "Host: foo.test\r\n" |
| 22890 | "Connection: keep-alive\r\n\r\n"), |
| 22891 | }; |
| 22892 | const MockRead kUnauthReads[] = { |
| 22893 | MockRead(ASYNC, 1, |
| 22894 | "HTTP/1.1 200 OK\r\n" |
| 22895 | "Connection: keep-alive\r\n" |
| 22896 | "Content-Length: 6\r\n\r\n" |
| 22897 | "unauth"), |
| 22898 | }; |
| 22899 | SequencedSocketData data_unauth(kUnauthReads, kUnauthWrites); |
| 22900 | SSLSocketDataProvider ssl_unauth(ASYNC, OK); |
| 22901 | session_deps_.socket_factory->AddSocketDataProvider(&data_unauth); |
| 22902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_unauth); |
| 22903 | |
| 22904 | // When the client certificate is selected, /auth is retried on a new |
| 22905 | // connection. In particular, it should not be retried on |data_unauth|, |
| 22906 | // which would not honor the new client certificate configuration. |
| 22907 | const MockWrite kRetryWrites[] = { |
| 22908 | MockWrite(ASYNC, 0, |
| 22909 | "GET /auth HTTP/1.1\r\n" |
| 22910 | "Host: foo.test\r\n" |
| 22911 | "Connection: keep-alive\r\n\r\n"), |
| 22912 | }; |
| 22913 | const MockRead kRetryReads[] = { |
| 22914 | MockRead(ASYNC, 1, |
| 22915 | "HTTP/1.1 200 OK\r\n" |
| 22916 | // Close the connection so we test that /post-auth is not |
| 22917 | // allocated to |data_unauth| or |data_long_lived|. |
| 22918 | "Connection: close\r\n" |
| 22919 | "Content-Length: 4\r\n\r\n" |
| 22920 | "auth"), |
| 22921 | }; |
| 22922 | SequencedSocketData data_retry(kRetryReads, kRetryWrites); |
| 22923 | SSLSocketDataProvider ssl_retry(ASYNC, OK); |
| 22924 | ssl_retry.expected_send_client_cert = true; |
| 22925 | ssl_retry.expected_client_cert = identity->certificate(); |
| 22926 | session_deps_.socket_factory->AddSocketDataProvider(&data_retry); |
| 22927 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_retry); |
| 22928 | |
| 22929 | // /post-auth gets its own socket. |
| 22930 | const MockWrite kPostAuthWrites[] = { |
| 22931 | MockWrite(ASYNC, 0, |
| 22932 | "GET /post-auth HTTP/1.1\r\n" |
| 22933 | "Host: foo.test\r\n" |
| 22934 | "Connection: keep-alive\r\n\r\n"), |
| 22935 | }; |
| 22936 | const MockRead kPostAuthReads[] = { |
| 22937 | MockRead(ASYNC, 1, |
| 22938 | "HTTP/1.1 200 OK\r\n" |
| 22939 | "Connection: keep-alive\r\n" |
| 22940 | "Content-Length: 9\r\n\r\n" |
| 22941 | "post-auth"), |
| 22942 | }; |
| 22943 | SequencedSocketData data_post_auth(kPostAuthReads, kPostAuthWrites); |
| 22944 | SSLSocketDataProvider ssl_post_auth(ASYNC, OK); |
| 22945 | ssl_post_auth.expected_send_client_cert = true; |
| 22946 | ssl_post_auth.expected_client_cert = identity->certificate(); |
| 22947 | session_deps_.socket_factory->AddSocketDataProvider(&data_post_auth); |
| 22948 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_post_auth); |
| 22949 | |
| 22950 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22951 | |
| 22952 | // Start the two long-lived requests. |
| 22953 | TestCompletionCallback callback_long_lived; |
| 22954 | auto trans_long_lived = |
| 22955 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22956 | int rv = trans_long_lived->Start( |
| 22957 | &request_long_lived, callback_long_lived.callback(), NetLogWithSource()); |
| 22958 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22959 | data_long_lived.RunUntilPaused(); |
| 22960 | |
| 22961 | TestCompletionCallback callback_long_lived_bar; |
| 22962 | auto trans_long_lived_bar = |
| 22963 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22964 | rv = trans_long_lived_bar->Start(&request_long_lived_bar, |
| 22965 | callback_long_lived_bar.callback(), |
| 22966 | NetLogWithSource()); |
| 22967 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22968 | data_bar.RunUntilPaused(); |
| 22969 | |
| 22970 | // Request /auth. This gives a client certificate challenge. |
| 22971 | TestCompletionCallback callback_auth; |
| 22972 | auto trans_auth = |
| 22973 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22974 | rv = trans_auth->Start(&request_auth, callback_auth.callback(), |
| 22975 | NetLogWithSource()); |
| 22976 | EXPECT_THAT(callback_auth.GetResult(rv), |
| 22977 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 22978 | |
| 22979 | // Make an unauthenticated request. This completes. |
| 22980 | TestCompletionCallback callback_unauth; |
| 22981 | auto trans_unauth = |
| 22982 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22983 | rv = trans_unauth->Start(&request_unauth, callback_unauth.callback(), |
| 22984 | NetLogWithSource()); |
| 22985 | EXPECT_THAT(callback_unauth.GetResult(rv), IsOk()); |
| 22986 | std::string response_unauth; |
| 22987 | EXPECT_THAT(ReadTransaction(trans_unauth.get(), &response_unauth), IsOk()); |
| 22988 | EXPECT_EQ("unauth", response_unauth); |
| 22989 | trans_unauth.reset(); |
| 22990 | |
| 22991 | // Complete the authenticated request. |
| 22992 | rv = trans_auth->RestartWithCertificate(identity->certificate(), |
| 22993 | identity->ssl_private_key(), |
| 22994 | callback_auth.callback()); |
| 22995 | EXPECT_THAT(callback_auth.GetResult(rv), IsOk()); |
| 22996 | std::string response_auth; |
| 22997 | EXPECT_THAT(ReadTransaction(trans_auth.get(), &response_auth), IsOk()); |
| 22998 | EXPECT_EQ("auth", response_auth); |
| 22999 | trans_auth.reset(); |
| 23000 | |
| 23001 | // Complete the long-lived requests. |
| 23002 | data_long_lived.Resume(); |
| 23003 | EXPECT_THAT(callback_long_lived.GetResult(ERR_IO_PENDING), IsOk()); |
| 23004 | std::string response_long_lived; |
| 23005 | EXPECT_THAT(ReadTransaction(trans_long_lived.get(), &response_long_lived), |
| 23006 | IsOk()); |
| 23007 | EXPECT_EQ("long-lived", response_long_lived); |
| 23008 | trans_long_lived.reset(); |
| 23009 | |
| 23010 | data_bar.Resume(); |
| 23011 | EXPECT_THAT(callback_long_lived_bar.GetResult(ERR_IO_PENDING), IsOk()); |
| 23012 | std::string response_long_lived_bar; |
| 23013 | EXPECT_THAT( |
| 23014 | ReadTransaction(trans_long_lived_bar.get(), &response_long_lived_bar), |
| 23015 | IsOk()); |
| 23016 | EXPECT_EQ("long-lived", response_long_lived_bar); |
| 23017 | trans_long_lived_bar.reset(); |
| 23018 | |
| 23019 | // Run the post-authentication requests. |
| 23020 | TestCompletionCallback callback_post_auth; |
| 23021 | auto trans_post_auth = |
| 23022 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23023 | rv = trans_post_auth->Start(&request_post_auth, callback_post_auth.callback(), |
| 23024 | NetLogWithSource()); |
| 23025 | EXPECT_THAT(callback_post_auth.GetResult(rv), IsOk()); |
| 23026 | std::string response_post_auth; |
| 23027 | EXPECT_THAT(ReadTransaction(trans_post_auth.get(), &response_post_auth), |
| 23028 | IsOk()); |
| 23029 | EXPECT_EQ("post-auth", response_post_auth); |
| 23030 | trans_post_auth.reset(); |
| 23031 | |
| 23032 | TestCompletionCallback callback_post_auth_bar; |
| 23033 | auto trans_post_auth_bar = |
| 23034 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23035 | rv = trans_post_auth_bar->Start(&request_post_auth_bar, |
| 23036 | callback_post_auth_bar.callback(), |
| 23037 | NetLogWithSource()); |
| 23038 | EXPECT_THAT(callback_post_auth_bar.GetResult(rv), IsOk()); |
| 23039 | std::string response_post_auth_bar; |
| 23040 | EXPECT_THAT( |
| 23041 | ReadTransaction(trans_post_auth_bar.get(), &response_post_auth_bar), |
| 23042 | IsOk()); |
| 23043 | EXPECT_EQ("post-auth", response_post_auth_bar); |
| 23044 | trans_post_auth_bar.reset(); |
| 23045 | } |
| 23046 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 23047 | } // namespace net |