[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" |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 46 | #include "net/base/ip_address.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 47 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 48 | #include "net/base/load_timing_info.h" |
| 49 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 50 | #include "net/base/net_errors.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 51 | #include "net/base/privacy_mode.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 52 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 53 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 54 | #include "net/base/request_priority.h" |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 55 | #include "net/base/schemeful_site.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 57 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 58 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 59 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 60 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 61 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 62 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 63 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 64 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 65 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 66 | #include "net/http/http_auth_handler_ntlm.h" |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 67 | #include "net/http/http_auth_ntlm_mechanism.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 68 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 69 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 70 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 71 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 72 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 73 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 74 | #include "net/http/http_response_info.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 75 | #include "net/http/http_server_properties.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 76 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 77 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 78 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 79 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 80 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 81 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 82 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 83 | #include "net/log/test_net_log_util.h" |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 84 | #include "net/proxy_resolution/configured_proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 85 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 86 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 87 | #include "net/proxy_resolution/proxy_info.h" |
| 88 | #include "net/proxy_resolution/proxy_resolver.h" |
| 89 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 90 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 91 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 92 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 93 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 94 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 95 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 96 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 97 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 98 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 99 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 100 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 101 | #include "net/spdy/spdy_session.h" |
| 102 | #include "net/spdy/spdy_session_pool.h" |
| 103 | #include "net/spdy/spdy_test_util_common.h" |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 104 | #include "net/ssl/client_cert_identity_test_util.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 105 | #include "net/ssl/ssl_cert_request_info.h" |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 106 | #include "net/ssl/ssl_config.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 107 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 108 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 109 | #include "net/ssl/ssl_private_key.h" |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 110 | #include "net/ssl/test_ssl_config_service.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 111 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 112 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 113 | #include "net/test/test_data_directory.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 114 | #include "net/test/test_with_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 115 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 116 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 117 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 118 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 119 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 120 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 121 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 122 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 123 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 124 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 125 | #if defined(NTLM_PORTABLE) |
| 126 | #include "base/base64.h" |
| 127 | #include "net/ntlm/ntlm_test_data.h" |
| 128 | #endif |
| 129 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 130 | #if BUILDFLAG(ENABLE_REPORTING) |
| 131 | #include "net/network_error_logging/network_error_logging_service.h" |
| 132 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 133 | #include "net/reporting/reporting_cache.h" |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 134 | #include "net/reporting/reporting_endpoint.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 135 | #include "net/reporting/reporting_header_parser.h" |
| 136 | #include "net/reporting/reporting_service.h" |
| 137 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 138 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 139 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 140 | using net::test::IsError; |
| 141 | using net::test::IsOk; |
| 142 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 143 | using base::ASCIIToUTF16; |
| 144 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 145 | using testing::AnyOf; |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 146 | using testing::ElementsAre; |
| 147 | using testing::IsEmpty; |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 148 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 149 | //----------------------------------------------------------------------------- |
| 150 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 151 | namespace net { |
| 152 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 153 | namespace { |
| 154 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 155 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 156 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 157 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 158 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 159 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 160 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 161 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 162 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 163 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 164 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 165 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 166 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 167 | const char kAlternativeServiceHttpHeader[] = |
| 168 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 169 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 170 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 171 | return session |
| 172 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 173 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 174 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 175 | } |
| 176 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 177 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 178 | return session |
| 179 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 180 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 182 | } |
| 183 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 184 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 185 | // a JSONified list of headers as a single string. Uses single quotes instead |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 186 | // of double quotes for easier comparison. |
| 187 | std::string GetHeaders(const base::Value& params) { |
| 188 | if (!params.is_dict()) |
| 189 | return ""; |
| 190 | const base::Value* header_list = params.FindListKey("headers"); |
| 191 | if (!header_list) |
| 192 | return ""; |
| 193 | std::string headers; |
| 194 | base::JSONWriter::Write(*header_list, &headers); |
| 195 | base::ReplaceChars(headers, "\"", "'", &headers); |
| 196 | return headers; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 200 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 202 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 203 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 204 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 206 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 207 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 208 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 209 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 210 | |
| 211 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 212 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 213 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 214 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 215 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 216 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 217 | } |
| 218 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 220 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 221 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 222 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 224 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | |
| 226 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 227 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 228 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 229 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 230 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 231 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 232 | load_timing_info.send_start); |
| 233 | |
| 234 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 236 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 238 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 239 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 243 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 244 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 245 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 246 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 247 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 248 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | |
| 250 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 251 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 252 | load_timing_info.proxy_resolve_end); |
| 253 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 254 | load_timing_info.send_start); |
| 255 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 256 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 257 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 258 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 259 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 260 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 264 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 265 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 266 | int connect_timing_flags) { |
| 267 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 268 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | |
| 270 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 271 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 272 | load_timing_info.proxy_resolve_end); |
| 273 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 274 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 275 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 276 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 277 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 278 | load_timing_info.send_start); |
| 279 | |
| 280 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 281 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 282 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 283 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 284 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 285 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 286 | } |
| 287 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 288 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 289 | // result to return. |
| 290 | class CapturingProxyResolver : public ProxyResolver { |
| 291 | public: |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 292 | struct LookupInfo { |
| 293 | GURL url; |
| 294 | NetworkIsolationKey network_isolation_key; |
| 295 | }; |
| 296 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 297 | CapturingProxyResolver() |
| 298 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 299 | ~CapturingProxyResolver() override = default; |
| 300 | |
| 301 | int GetProxyForURL(const GURL& url, |
Matt Menke | cd522ee0 | 2019-11-13 19:53:39 | [diff] [blame] | 302 | const NetworkIsolationKey& network_isolation_key, |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 303 | ProxyInfo* results, |
| 304 | CompletionOnceCallback callback, |
| 305 | std::unique_ptr<Request>* request, |
| 306 | const NetLogWithSource& net_log) override { |
| 307 | results->UseProxyServer(proxy_server_); |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 308 | lookup_info_.push_back(LookupInfo{url, network_isolation_key}); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 309 | return OK; |
| 310 | } |
| 311 | |
| 312 | // Sets whether the resolver should use direct connections, instead of a |
| 313 | // proxy. |
| 314 | void set_proxy_server(ProxyServer proxy_server) { |
| 315 | proxy_server_ = proxy_server; |
| 316 | } |
| 317 | |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 318 | const std::vector<LookupInfo>& lookup_info() const { return lookup_info_; } |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 319 | |
| 320 | private: |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 321 | std::vector<LookupInfo> lookup_info_; |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 322 | |
| 323 | ProxyServer proxy_server_; |
| 324 | |
| 325 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 326 | }; |
| 327 | |
| 328 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 329 | public: |
| 330 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 331 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 332 | |
| 333 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 334 | std::unique_ptr<ProxyResolver>* resolver, |
| 335 | CompletionOnceCallback callback, |
| 336 | std::unique_ptr<Request>* request) override { |
| 337 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 338 | return OK; |
| 339 | } |
| 340 | |
| 341 | private: |
| 342 | ProxyResolver* resolver_; |
| 343 | }; |
| 344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 345 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 346 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 347 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 348 | } |
| 349 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 350 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 351 | public: |
| 352 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 353 | |
| 354 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 355 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 356 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 357 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 358 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 359 | return ERR_PAC_SCRIPT_FAILED; |
| 360 | } |
| 361 | }; |
| 362 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 363 | // A default minimal HttpRequestInfo for use in tests, targeting HTTP. |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 364 | HttpRequestInfo DefaultRequestInfo() { |
| 365 | HttpRequestInfo info; |
| 366 | info.method = "GET"; |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 367 | info.url = GURL("http://foo.test"); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 368 | info.traffic_annotation = |
| 369 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 370 | return info; |
| 371 | } |
| 372 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 373 | // The default info for transports to the embedded HTTP server. |
| 374 | TransportInfo EmbeddedHttpServerTransportInfo() { |
| 375 | TransportInfo info; |
| 376 | info.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 80); |
| 377 | return info; |
| 378 | } |
| 379 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 380 | } // namespace |
| 381 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 382 | class HttpNetworkTransactionTest : public PlatformTest, |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 383 | public WithTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 384 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 385 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 386 | // Important to restore the per-pool limit first, since the pool limit must |
| 387 | // always be greater than group limit, and the tests reduce both limits. |
| 388 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 389 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 390 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 391 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 392 | } |
| 393 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 394 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 395 | HttpNetworkTransactionTest() |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 396 | : WithTaskEnvironment(base::test::TaskEnvironment::TimeSource::MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 397 | dummy_connect_job_params_( |
| 398 | nullptr /* client_socket_factory */, |
| 399 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 400 | nullptr /* http_auth_cache */, |
| 401 | nullptr /* http_auth_handler_factory */, |
| 402 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 403 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 404 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 405 | nullptr /* proxy_delegate */, |
| 406 | nullptr /* http_user_agent_settings */, |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 407 | nullptr /* ssl_client_context */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 408 | nullptr /* socket_performance_watcher_factory */, |
| 409 | nullptr /* network_quality_estimator */, |
| 410 | nullptr /* net_log */, |
| 411 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 412 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 413 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 414 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 415 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 416 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 417 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 418 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 419 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 420 | struct SimpleGetHelperResult { |
| 421 | int rv; |
| 422 | std::string status_line; |
| 423 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 424 | int64_t total_received_bytes; |
| 425 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 426 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 427 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 428 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 429 | }; |
| 430 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 431 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 432 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 433 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 434 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 435 | // before incrementing the counter does not return a null value. |
Matt Menke | 6dc0823 | 2019-10-03 18:00:28 | [diff] [blame] | 436 | FastForwardBy(base::TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 437 | } |
| 438 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 439 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 440 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 441 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 442 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 443 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 444 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 445 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 446 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 447 | } |
| 448 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 449 | void Check100ResponseTiming(bool use_spdy); |
| 450 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 451 | // Either |write_failure| specifies a write failure or |read_failure| |
| 452 | // specifies a read failure when using a reused socket. In either case, the |
| 453 | // failure should cause the network transaction to resend the request, and the |
| 454 | // other argument should be NULL. |
| 455 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 456 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 457 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 458 | // Either |write_failure| specifies a write failure or |read_failure| |
| 459 | // specifies a read failure when using a reused socket. In either case, the |
| 460 | // failure should cause the network transaction to resend the request, and the |
| 461 | // other argument should be NULL. |
| 462 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 463 | const MockRead* read_failure, |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 464 | bool use_spdy, |
| 465 | bool upload = false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 466 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 467 | SimpleGetHelperResult SimpleGetHelperForData( |
| 468 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 469 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 470 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 471 | HttpRequestInfo request; |
| 472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 473 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 474 | request.traffic_annotation = |
| 475 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 476 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 477 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 478 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 480 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 481 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 482 | for (auto* provider : providers) { |
| 483 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 484 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 486 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 487 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 488 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 489 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 491 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 492 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 493 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 494 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 495 | |
| 496 | // Even in the failure cases that use this function, connections are always |
| 497 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 498 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 499 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 500 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 501 | if (out.rv != OK) |
| 502 | return out; |
| 503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 504 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 505 | // Can't use ASSERT_* inside helper functions like this, so |
| 506 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 507 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 508 | out.rv = ERR_UNEXPECTED; |
| 509 | return out; |
| 510 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 511 | out.status_line = response->headers->GetStatusLine(); |
| 512 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 513 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 514 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 515 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 516 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 517 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 518 | EXPECT_EQ(got_endpoint, |
| 519 | out.remote_endpoint_after_start.address().size() > 0); |
| 520 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 521 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 522 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 523 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 524 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 525 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 526 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 527 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 528 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 529 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 530 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 531 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 532 | EXPECT_EQ("GET / HTTP/1.1\r\n", |
| 533 | GetStringValueFromParams(entries[pos], "line")); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 534 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 535 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 536 | GetHeaders(entries[pos].params)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 538 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 539 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 540 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 542 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 543 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 544 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 545 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 546 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 547 | MockWrite data_writes[] = { |
| 548 | MockWrite("GET / HTTP/1.1\r\n" |
| 549 | "Host: www.example.org\r\n" |
| 550 | "Connection: keep-alive\r\n\r\n"), |
| 551 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 552 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 553 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 554 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 555 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 556 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 557 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 558 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 559 | } |
| 560 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 561 | void AddSSLSocketData() { |
| 562 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 563 | ssl_.ssl_info.cert = |
| 564 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 565 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 567 | } |
| 568 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 569 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 570 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 571 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 572 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 573 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 574 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 575 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 576 | base::RepeatingClosure FastForwardByCallback(base::TimeDelta delta) { |
| 577 | return base::BindRepeating(&HttpNetworkTransactionTest::FastForwardBy, |
| 578 | base::Unretained(this), delta); |
| 579 | } |
| 580 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 581 | const CommonConnectJobParams dummy_connect_job_params_; |
| 582 | |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 583 | const net::NetworkIsolationKey kNetworkIsolationKey = |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 584 | NetworkIsolationKey(SchemefulSite(GURL("https://foo.test/")), |
| 585 | SchemefulSite(GURL("https://bar.test/"))); |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 586 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 587 | // These clocks are defined here, even though they're only used in the |
| 588 | // Reporting tests below, since they need to be destroyed after |
| 589 | // |session_deps_|. |
| 590 | base::SimpleTestClock clock_; |
| 591 | base::SimpleTestTickClock tick_clock_; |
| 592 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 593 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 594 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 595 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 596 | |
| 597 | // Original socket limits. Some tests set these. Safest to always restore |
| 598 | // them once each test has been run. |
| 599 | int old_max_group_sockets_; |
| 600 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 601 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 602 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 603 | namespace { |
| 604 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 605 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 606 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 607 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 608 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 609 | const int sizeof_row = strlen(row); |
| 610 | const int num_rows = static_cast<int>( |
| 611 | ceil(static_cast<float>(size) / sizeof_row)); |
| 612 | const int sizeof_data = num_rows * sizeof_row; |
| 613 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 614 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 615 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 616 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 617 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 618 | } |
| 619 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 620 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 621 | uint64_t MockGetMSTime() { |
| 622 | // Tue, 23 May 2017 20:13:07 +0000 |
| 623 | return 131400439870000000; |
| 624 | } |
| 625 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 626 | // Alternative functions that eliminate randomness and dependency on the local |
| 627 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 628 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 629 | // This is set to 0xaa because the client challenge for testing in |
| 630 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 631 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 632 | } |
| 633 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 634 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 635 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 636 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 637 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 638 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 639 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 640 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 641 | explicit CaptureGroupIdTransportSocketPool( |
| 642 | const CommonConnectJobParams* common_connect_job_params) |
| 643 | : TransportClientSocketPool(0, |
| 644 | 0, |
| 645 | base::TimeDelta(), |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 646 | ProxyServer::Direct(), |
| 647 | false /* is_for_websockets */, |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 648 | common_connect_job_params) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 649 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 650 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 651 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 652 | } |
| 653 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 654 | bool socket_requested() const { return socket_requested_; } |
| 655 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 656 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 657 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 658 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 659 | const base::Optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 660 | RequestPriority priority, |
| 661 | const SocketTag& socket_tag, |
| 662 | ClientSocketPool::RespectLimits respect_limits, |
| 663 | ClientSocketHandle* handle, |
| 664 | CompletionOnceCallback callback, |
| 665 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 666 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 667 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 668 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 669 | return ERR_IO_PENDING; |
| 670 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 671 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 672 | ClientSocketHandle* handle, |
| 673 | bool cancel_connect_job) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 674 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 675 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 676 | int64_t generation) override {} |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 677 | void CloseIdleSockets(const char* net_log_reason_utf8) override {} |
| 678 | void CloseIdleSocketsInGroup(const ClientSocketPool::GroupId& group_id, |
| 679 | const char* net_log_reason_utf8) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 680 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 681 | size_t IdleSocketCountInGroup( |
| 682 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 683 | return 0; |
| 684 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 685 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 686 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 687 | return LOAD_STATE_IDLE; |
| 688 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 689 | |
| 690 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 691 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 692 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 693 | }; |
| 694 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 695 | //----------------------------------------------------------------------------- |
| 696 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 697 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 698 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 699 | bool CheckBasicServerAuth( |
| 700 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 701 | if (!auth_challenge) |
| 702 | return false; |
| 703 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 704 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 705 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 706 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 707 | return true; |
| 708 | } |
| 709 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 710 | bool CheckBasicSecureServerAuth( |
| 711 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
| 712 | if (!auth_challenge) |
| 713 | return false; |
| 714 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 715 | EXPECT_EQ("https://www.example.org", auth_challenge->challenger.Serialize()); |
| 716 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 717 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 718 | return true; |
| 719 | } |
| 720 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 721 | bool CheckBasicProxyAuth( |
| 722 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 723 | if (!auth_challenge) |
| 724 | return false; |
| 725 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 726 | EXPECT_EQ("http://myproxy:70", 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 CheckBasicSecureProxyAuth( |
| 733 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 734 | if (!auth_challenge) |
| 735 | return false; |
| 736 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 737 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 738 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 739 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 740 | return true; |
| 741 | } |
| 742 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 743 | bool CheckDigestServerAuth( |
| 744 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 745 | if (!auth_challenge) |
| 746 | return false; |
| 747 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 748 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 749 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 750 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 751 | return true; |
| 752 | } |
| 753 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 754 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 755 | bool CheckNTLMServerAuth( |
| 756 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 757 | if (!auth_challenge) |
| 758 | return false; |
| 759 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 760 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 761 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 762 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 763 | return true; |
| 764 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 765 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 766 | bool CheckNTLMProxyAuth( |
| 767 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 768 | if (!auth_challenge) |
| 769 | return false; |
| 770 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 771 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 772 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 773 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 774 | return true; |
| 775 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 776 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 777 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 778 | } // namespace |
| 779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 780 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 781 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | } |
| 784 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 785 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 786 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 787 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 788 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 789 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 790 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 791 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 792 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 793 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 794 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 795 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 796 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 797 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 798 | |
| 799 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 803 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 804 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 805 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 806 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 807 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 808 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 809 | EXPECT_THAT(out.rv, IsOk()); |
| 810 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 811 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 812 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 813 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | } |
| 815 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 816 | // Response with no status line, and a weird port. Should fail by default. |
| 817 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 818 | MockRead data_reads[] = { |
| 819 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 820 | }; |
| 821 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 822 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 823 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 824 | |
| 825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 826 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 827 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 828 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 829 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 830 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 831 | request.method = "GET"; |
| 832 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 833 | request.traffic_annotation = |
| 834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 835 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 836 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 837 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 838 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 839 | } |
| 840 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 841 | // Tests that request info can be destroyed after the headers phase is complete. |
| 842 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 844 | auto trans = |
| 845 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 846 | |
| 847 | MockRead data_reads[] = { |
| 848 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 849 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 850 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 851 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 853 | |
| 854 | TestCompletionCallback callback; |
| 855 | |
| 856 | { |
| 857 | auto request = std::make_unique<HttpRequestInfo>(); |
| 858 | request->method = "GET"; |
| 859 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 860 | request->traffic_annotation = |
| 861 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 862 | |
| 863 | int rv = |
| 864 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 865 | |
| 866 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 867 | } // Let request info be destroyed. |
| 868 | |
| 869 | trans.reset(); |
| 870 | } |
| 871 | |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 872 | // Test that a failure in resolving the hostname is retrievable. |
| 873 | TEST_F(HttpNetworkTransactionTest, SimpleGETHostResolutionFailure) { |
| 874 | HttpRequestInfo request; |
| 875 | request.method = "GET"; |
| 876 | request.url = GURL("http://www.example.org/"); |
| 877 | request.traffic_annotation = |
| 878 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 879 | |
| 880 | RecordingTestNetLog log; |
| 881 | MockHostResolver* resolver = new MockHostResolver(); |
| 882 | resolver->rules()->AddSimulatedTimeoutFailure("www.example.org"); |
| 883 | session_deps_.net_log = &log; |
| 884 | session_deps_.host_resolver.reset(resolver); |
| 885 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 887 | TestCompletionCallback callback; |
| 888 | |
| 889 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 891 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 892 | |
| 893 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 894 | ASSERT_TRUE(response); |
| 895 | EXPECT_THAT(response->resolve_error_info.error, IsError(ERR_DNS_TIMED_OUT)); |
| 896 | } |
| 897 | |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 898 | // This test verifies that if the transaction fails before even connecting to a |
| 899 | // remote endpoint, the ConnectedCallback is never called. |
| 900 | TEST_F(HttpNetworkTransactionTest, ConnectedCallbackNeverCalled) { |
| 901 | auto resolver = std::make_unique<MockHostResolver>(); |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 902 | resolver->rules()->AddSimulatedTimeoutFailure("bar.test"); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 903 | session_deps_.host_resolver = std::move(resolver); |
| 904 | |
| 905 | ConnectedHandler connected_handler; |
| 906 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 907 | |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 908 | auto request = DefaultRequestInfo(); |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 909 | request.url = GURL("http://bar.test"); |
| 910 | |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 911 | HttpNetworkTransaction transaction(DEFAULT_PRIORITY, session.get()); |
| 912 | transaction.SetConnectedCallback(connected_handler.Callback()); |
| 913 | |
| 914 | TestCompletionCallback callback; |
| 915 | transaction.Start(&request, callback.callback(), NetLogWithSource()); |
| 916 | callback.WaitForResult(); |
| 917 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 918 | EXPECT_THAT(connected_handler.transports(), IsEmpty()); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | // This test verifies that if the ConnectedCallback returns an error, the |
| 922 | // entire transaction fails with that error. |
| 923 | TEST_F(HttpNetworkTransactionTest, ConnectedCallbackFailure) { |
| 924 | // The exact error code does not matter, as long as it is the same one |
| 925 | // returned by the transaction overall. |
| 926 | ConnectedHandler connected_handler; |
| 927 | connected_handler.set_result(ERR_NOT_IMPLEMENTED); |
| 928 | |
| 929 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 930 | auto request = DefaultRequestInfo(); |
| 931 | HttpNetworkTransaction transaction(DEFAULT_PRIORITY, session.get()); |
| 932 | transaction.SetConnectedCallback(connected_handler.Callback()); |
| 933 | |
| 934 | // We never get to writing any data, but we still need a socket. |
| 935 | StaticSocketDataProvider data; |
| 936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 937 | |
| 938 | TestCompletionCallback callback; |
| 939 | EXPECT_THAT( |
| 940 | transaction.Start(&request, callback.callback(), NetLogWithSource()), |
| 941 | IsError(ERR_IO_PENDING)); |
| 942 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NOT_IMPLEMENTED)); |
| 943 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 944 | EXPECT_THAT(connected_handler.transports(), |
| 945 | ElementsAre(EmbeddedHttpServerTransportInfo())); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | // This test verifies that the ConnectedCallback is called once in the case of |
| 949 | // simple requests. |
| 950 | TEST_F(HttpNetworkTransactionTest, ConnectedCallbackCalledOnce) { |
| 951 | MockRead data_reads[] = { |
| 952 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 953 | MockRead(SYNCHRONOUS, OK), |
| 954 | }; |
| 955 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 957 | |
| 958 | ConnectedHandler connected_handler; |
| 959 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 960 | auto request = DefaultRequestInfo(); |
| 961 | HttpNetworkTransaction transaction(DEFAULT_PRIORITY, session.get()); |
| 962 | transaction.SetConnectedCallback(connected_handler.Callback()); |
| 963 | |
| 964 | TestCompletionCallback callback; |
| 965 | EXPECT_THAT( |
| 966 | transaction.Start(&request, callback.callback(), NetLogWithSource()), |
| 967 | IsError(ERR_IO_PENDING)); |
| 968 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 969 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 970 | EXPECT_THAT(connected_handler.transports(), |
| 971 | ElementsAre(EmbeddedHttpServerTransportInfo())); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | // This test verifies that the ConnectedCallback is called once more per |
| 975 | // authentication challenge. |
| 976 | TEST_F(HttpNetworkTransactionTest, ConnectedCallbackCalledOnEachAuthChallenge) { |
| 977 | ConnectedHandler connected_handler; |
| 978 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 979 | auto request = DefaultRequestInfo(); |
| 980 | HttpNetworkTransaction transaction(DEFAULT_PRIORITY, session.get()); |
| 981 | transaction.SetConnectedCallback(connected_handler.Callback()); |
| 982 | |
| 983 | // First request receives an auth challenge. |
| 984 | MockRead data_reads1[] = { |
| 985 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 986 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 987 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 988 | }; |
| 989 | StaticSocketDataProvider data1(data_reads1, base::span<MockWrite>()); |
| 990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 991 | |
| 992 | // Second request is allowed through. |
| 993 | MockRead data_reads2[] = { |
| 994 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 995 | MockRead(SYNCHRONOUS, OK), |
| 996 | }; |
| 997 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 998 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 999 | |
| 1000 | // First request, connects once. |
| 1001 | TestCompletionCallback callback1; |
| 1002 | EXPECT_THAT( |
| 1003 | transaction.Start(&request, callback1.callback(), NetLogWithSource()), |
| 1004 | IsError(ERR_IO_PENDING)); |
| 1005 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1006 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 1007 | EXPECT_THAT(connected_handler.transports(), |
| 1008 | ElementsAre(EmbeddedHttpServerTransportInfo())); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 1009 | |
| 1010 | // Second request, connects again. |
| 1011 | TestCompletionCallback callback2; |
| 1012 | EXPECT_THAT(transaction.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 1013 | callback2.callback()), |
| 1014 | IsError(ERR_IO_PENDING)); |
| 1015 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 1016 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 1017 | EXPECT_THAT(connected_handler.transports(), |
| 1018 | ElementsAre(EmbeddedHttpServerTransportInfo(), |
| 1019 | EmbeddedHttpServerTransportInfo())); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | // This test verifies that the ConnectedCallback is called once more per retry. |
| 1023 | TEST_F(HttpNetworkTransactionTest, ConnectedCallbackCalledOnEachRetry) { |
| 1024 | ConnectedHandler connected_handler; |
| 1025 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 1026 | auto request = DefaultRequestInfo(); |
| 1027 | HttpNetworkTransaction transaction(DEFAULT_PRIORITY, session.get()); |
| 1028 | transaction.SetConnectedCallback(connected_handler.Callback()); |
| 1029 | |
| 1030 | // First request receives a retryable error. |
| 1031 | MockRead data_reads1[] = { |
| 1032 | MockRead(SYNCHRONOUS, ERR_HTTP2_SERVER_REFUSED_STREAM), |
| 1033 | }; |
| 1034 | StaticSocketDataProvider data1(data_reads1, base::span<MockWrite>()); |
| 1035 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1036 | |
| 1037 | // Second request is allowed through. |
| 1038 | MockRead data_reads2[] = { |
| 1039 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1040 | MockRead(SYNCHRONOUS, OK), |
| 1041 | }; |
| 1042 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 1043 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1044 | |
| 1045 | TestCompletionCallback callback1; |
| 1046 | EXPECT_THAT( |
| 1047 | transaction.Start(&request, callback1.callback(), NetLogWithSource()), |
| 1048 | IsError(ERR_IO_PENDING)); |
| 1049 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 1050 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 1051 | EXPECT_THAT(connected_handler.transports(), |
| 1052 | ElementsAre(EmbeddedHttpServerTransportInfo(), |
| 1053 | EmbeddedHttpServerTransportInfo())); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 1054 | } |
| 1055 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1056 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1057 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1058 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1059 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1060 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1061 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1062 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1063 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1064 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 1065 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1066 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1067 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1071 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1072 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1073 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1074 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1075 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1076 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1077 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1078 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 1079 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1080 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1081 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1085 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1086 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1087 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1088 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1089 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1090 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1091 | EXPECT_THAT(out.rv, IsOk()); |
| 1092 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1093 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1094 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1095 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1099 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1100 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1101 | MockRead("\n"), |
| 1102 | MockRead("\n"), |
| 1103 | MockRead("Q"), |
| 1104 | MockRead("J"), |
| 1105 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1106 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1107 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1108 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1109 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1110 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 1111 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1112 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1113 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1117 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1118 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1119 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1120 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1121 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1122 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1123 | EXPECT_THAT(out.rv, IsOk()); |
| 1124 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1125 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1126 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1127 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1128 | } |
| 1129 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1130 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1131 | // persistent connection. The response should still terminate since a 204 |
| 1132 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1133 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1134 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1135 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1136 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1137 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1138 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1139 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1140 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1141 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1142 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1143 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1144 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1145 | int64_t response_size = reads_size - strlen(junk); |
| 1146 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1147 | } |
| 1148 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1149 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1150 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1151 | std::string final_chunk = "0\r\n\r\n"; |
| 1152 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1153 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1154 | MockRead data_reads[] = { |
| 1155 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1156 | MockRead("5\r\nHello\r\n"), |
| 1157 | MockRead("1\r\n"), |
| 1158 | MockRead(" \r\n"), |
| 1159 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1160 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1161 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1162 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1163 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1164 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1165 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1166 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1167 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1168 | int64_t response_size = reads_size - extra_data.size(); |
| 1169 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1170 | } |
| 1171 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1172 | // Next tests deal with http://crbug.com/56344. |
| 1173 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1174 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1175 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1176 | MockRead data_reads[] = { |
| 1177 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1178 | MockRead("Content-Length: 10\r\n"), |
| 1179 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1180 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1181 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1182 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1183 | } |
| 1184 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1185 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1186 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1187 | MockRead data_reads[] = { |
| 1188 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1189 | MockRead("Content-Length: 5\r\n"), |
| 1190 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1191 | MockRead("Hello"), |
| 1192 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1193 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1194 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1195 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1196 | EXPECT_EQ("Hello", out.response_data); |
| 1197 | } |
| 1198 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1199 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1200 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1201 | // More than 2 dupes. |
| 1202 | { |
| 1203 | MockRead data_reads[] = { |
| 1204 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1205 | MockRead("Content-Length: 5\r\n"), |
| 1206 | MockRead("Content-Length: 5\r\n"), |
| 1207 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1208 | MockRead("Hello"), |
| 1209 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1210 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1211 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1212 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1213 | EXPECT_EQ("Hello", out.response_data); |
| 1214 | } |
| 1215 | // HTTP/1.0 |
| 1216 | { |
| 1217 | MockRead data_reads[] = { |
| 1218 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1219 | MockRead("Content-Length: 5\r\n"), |
| 1220 | MockRead("Content-Length: 5\r\n"), |
| 1221 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1222 | MockRead("Hello"), |
| 1223 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1224 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1225 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1226 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1227 | EXPECT_EQ("Hello", out.response_data); |
| 1228 | } |
| 1229 | // 2 dupes and one mismatched. |
| 1230 | { |
| 1231 | MockRead data_reads[] = { |
| 1232 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1233 | MockRead("Content-Length: 10\r\n"), |
| 1234 | MockRead("Content-Length: 10\r\n"), |
| 1235 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1236 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1237 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1238 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1242 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1243 | MultipleContentLengthHeadersTransferEncoding) { |
| 1244 | MockRead data_reads[] = { |
| 1245 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1246 | MockRead("Content-Length: 666\r\n"), |
| 1247 | MockRead("Content-Length: 1337\r\n"), |
| 1248 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1249 | MockRead("5\r\nHello\r\n"), |
| 1250 | MockRead("1\r\n"), |
| 1251 | MockRead(" \r\n"), |
| 1252 | MockRead("5\r\nworld\r\n"), |
| 1253 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1254 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1255 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1256 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1257 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1258 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1259 | EXPECT_EQ("Hello world", out.response_data); |
| 1260 | } |
| 1261 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1262 | // Next tests deal with http://crbug.com/98895. |
| 1263 | |
| 1264 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1265 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1266 | MockRead data_reads[] = { |
| 1267 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1268 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1269 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1270 | MockRead("Hello"), |
| 1271 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1272 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1273 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1274 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1275 | EXPECT_EQ("Hello", out.response_data); |
| 1276 | } |
| 1277 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1278 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1279 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1280 | MockRead data_reads[] = { |
| 1281 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1282 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1283 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1284 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1285 | MockRead("Hello"), |
| 1286 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1287 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1288 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1289 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1290 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1294 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1295 | MockRead data_reads[] = { |
| 1296 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1297 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1298 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1299 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1300 | MockRead("Hello"), |
| 1301 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1302 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1303 | EXPECT_THAT(out.rv, |
| 1304 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1305 | } |
| 1306 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1307 | // Checks that two identical Location headers result in no error. |
| 1308 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1309 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1310 | MockRead data_reads[] = { |
| 1311 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1312 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1313 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1314 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1315 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1316 | }; |
| 1317 | |
| 1318 | HttpRequestInfo request; |
| 1319 | request.method = "GET"; |
| 1320 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1321 | request.traffic_annotation = |
| 1322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1326 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1327 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1330 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1331 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1332 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1334 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1335 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1336 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1337 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1338 | ASSERT_TRUE(response); |
| 1339 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1340 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1341 | std::string url; |
| 1342 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1343 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1344 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1345 | } |
| 1346 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1347 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1348 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1349 | MockRead data_reads[] = { |
| 1350 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1351 | MockRead("Location: http://good.com/\r\n"), |
| 1352 | MockRead("Location: http://evil.com/\r\n"), |
| 1353 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1354 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1355 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1356 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1357 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1358 | } |
| 1359 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1360 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1361 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1362 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1363 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1364 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1365 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1366 | request.traffic_annotation = |
| 1367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1368 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 1371 | ConnectedHandler connected_handler; |
| 1372 | trans.SetConnectedCallback(connected_handler.Callback()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1373 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1374 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1375 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1376 | "Host: www.example.org\r\n" |
| 1377 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1378 | }; |
| 1379 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1380 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1381 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1382 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1383 | // No response body because the test stops reading here. |
| 1384 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1385 | }; |
| 1386 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1387 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1388 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1390 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1392 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1394 | |
| 1395 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1399 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1400 | |
| 1401 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1402 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1403 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1404 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1405 | EXPECT_TRUE(response->proxy_server.is_direct()); |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 1406 | EXPECT_THAT(connected_handler.transports(), |
| 1407 | ElementsAre(EmbeddedHttpServerTransportInfo())); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1408 | |
| 1409 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1410 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1411 | bool has_server_header = response->headers->EnumerateHeader( |
| 1412 | &iter, "Server", &server_header); |
| 1413 | EXPECT_TRUE(has_server_header); |
| 1414 | EXPECT_EQ("Blah", server_header); |
| 1415 | |
| 1416 | // Reading should give EOF right away, since there is no message body |
| 1417 | // (despite non-zero content-length). |
| 1418 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1419 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1421 | EXPECT_EQ("", response_data); |
| 1422 | } |
| 1423 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1424 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1426 | |
| 1427 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1428 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1429 | MockRead("hello"), |
| 1430 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1431 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1432 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1433 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1434 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1436 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1437 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1438 | "hello", "world" |
| 1439 | }; |
| 1440 | |
| 1441 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1442 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1443 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1444 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1445 | request.traffic_annotation = |
| 1446 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1448 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1450 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1451 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1452 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1454 | |
| 1455 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1456 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1459 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1460 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1461 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1462 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1463 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1464 | |
| 1465 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1466 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1468 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1472 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1473 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1474 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1475 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1476 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1477 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1478 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1479 | request.method = "POST"; |
| 1480 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1481 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1482 | request.traffic_annotation = |
| 1483 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1484 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1485 | // Check the upload progress returned before initialization is correct. |
| 1486 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1487 | EXPECT_EQ(0u, progress.size()); |
| 1488 | EXPECT_EQ(0u, progress.position()); |
| 1489 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1492 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1493 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1494 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1495 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1496 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1497 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1498 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1499 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1502 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1503 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1504 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1506 | |
| 1507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1508 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1510 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1511 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1512 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1513 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1514 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1515 | |
| 1516 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1517 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1518 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1519 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1520 | } |
| 1521 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1522 | // This test is almost the same as Ignores100 above, but the response contains |
| 1523 | // 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] | 1524 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1525 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1526 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1527 | request.method = "GET"; |
| 1528 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1529 | request.traffic_annotation = |
| 1530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1531 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1532 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1533 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1534 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1535 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1536 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1537 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1538 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1539 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1540 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1541 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1544 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1546 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1548 | |
| 1549 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1552 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1553 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1554 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1555 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1556 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1557 | |
| 1558 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1559 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1561 | EXPECT_EQ("hello world", response_data); |
| 1562 | } |
| 1563 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1564 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1565 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1566 | base::TimeDelta::FromMilliseconds(10); |
| 1567 | |
| 1568 | HttpRequestInfo request; |
| 1569 | request.method = "GET"; |
| 1570 | request.url = GURL("http://www.foo.com/"); |
| 1571 | request.traffic_annotation = |
| 1572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1573 | |
| 1574 | std::vector<MockWrite> data_writes = { |
| 1575 | MockWrite(ASYNC, 0, |
| 1576 | "GET / HTTP/1.1\r\n" |
| 1577 | "Host: www.foo.com\r\n" |
| 1578 | "Connection: keep-alive\r\n\r\n"), |
| 1579 | }; |
| 1580 | |
| 1581 | std::vector<MockRead> data_reads = { |
| 1582 | // Write one byte of the status line, followed by a pause. |
| 1583 | MockRead(ASYNC, 1, "H"), |
| 1584 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1585 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1586 | MockRead(ASYNC, 4, "hello world"), |
| 1587 | MockRead(SYNCHRONOUS, OK, 5), |
| 1588 | }; |
| 1589 | |
| 1590 | SequencedSocketData data(data_reads, data_writes); |
| 1591 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1592 | |
| 1593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1594 | |
| 1595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1596 | |
| 1597 | TestCompletionCallback callback; |
| 1598 | |
| 1599 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1601 | |
| 1602 | data.RunUntilPaused(); |
| 1603 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1604 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1605 | data.Resume(); |
| 1606 | |
| 1607 | rv = callback.WaitForResult(); |
| 1608 | EXPECT_THAT(rv, IsOk()); |
| 1609 | |
| 1610 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1611 | ASSERT_TRUE(response); |
| 1612 | |
| 1613 | EXPECT_TRUE(response->headers); |
| 1614 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1615 | |
| 1616 | LoadTimingInfo load_timing_info; |
| 1617 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1618 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1619 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1620 | // Ensure we didn't include the delay in the TTFB time. |
| 1621 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1622 | load_timing_info.connect_timing.connect_end); |
| 1623 | // Ensure that the mock clock advanced at all. |
| 1624 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1625 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1626 | |
| 1627 | std::string response_data; |
| 1628 | rv = ReadTransaction(&trans, &response_data); |
| 1629 | EXPECT_THAT(rv, IsOk()); |
| 1630 | EXPECT_EQ("hello world", response_data); |
| 1631 | } |
| 1632 | |
| 1633 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1634 | // info uses the first response, even if 1XX/informational. |
| 1635 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1636 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1637 | base::TimeDelta::FromMilliseconds(10); |
| 1638 | |
| 1639 | HttpRequestInfo request; |
| 1640 | request.method = "GET"; |
| 1641 | request.url = GURL("https://www.foo.com/"); |
| 1642 | request.traffic_annotation = |
| 1643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1644 | |
| 1645 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1647 | |
| 1648 | std::vector<MockWrite> data_writes; |
| 1649 | std::vector<MockRead> data_reads; |
| 1650 | |
| 1651 | spdy::SpdySerializedFrame spdy_req( |
| 1652 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1653 | |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 1654 | spdy::Http2HeaderBlock spdy_resp1_headers; |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1655 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1656 | spdy::SpdySerializedFrame spdy_resp1( |
| 1657 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1658 | spdy::SpdySerializedFrame spdy_resp2( |
| 1659 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1660 | spdy::SpdySerializedFrame spdy_data( |
| 1661 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1662 | |
| 1663 | if (use_spdy) { |
| 1664 | ssl.next_proto = kProtoHTTP2; |
| 1665 | |
| 1666 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1667 | |
| 1668 | data_reads = { |
| 1669 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1670 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1671 | MockRead(SYNCHRONOUS, OK, 5), |
| 1672 | }; |
| 1673 | } else { |
| 1674 | data_writes = { |
| 1675 | MockWrite(ASYNC, 0, |
| 1676 | "GET / HTTP/1.1\r\n" |
| 1677 | "Host: www.foo.com\r\n" |
| 1678 | "Connection: keep-alive\r\n\r\n"), |
| 1679 | }; |
| 1680 | |
| 1681 | data_reads = { |
| 1682 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1683 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1684 | |
| 1685 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1686 | MockRead(ASYNC, 4, "hello world"), |
| 1687 | MockRead(SYNCHRONOUS, OK, 5), |
| 1688 | }; |
| 1689 | } |
| 1690 | |
| 1691 | SequencedSocketData data(data_reads, data_writes); |
| 1692 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1693 | |
| 1694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1695 | |
| 1696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1697 | |
| 1698 | TestCompletionCallback callback; |
| 1699 | |
| 1700 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1702 | |
| 1703 | data.RunUntilPaused(); |
| 1704 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1705 | // the delay before parsing the 200 response. |
| 1706 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1707 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1708 | data.Resume(); |
| 1709 | |
| 1710 | rv = callback.WaitForResult(); |
| 1711 | EXPECT_THAT(rv, IsOk()); |
| 1712 | |
| 1713 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1714 | ASSERT_TRUE(response); |
| 1715 | |
| 1716 | LoadTimingInfo load_timing_info; |
| 1717 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1718 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1719 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1720 | // Ensure we didn't include the delay in the TTFB time. |
| 1721 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1722 | load_timing_info.connect_timing.connect_end); |
| 1723 | // Ensure that the mock clock advanced at all. |
| 1724 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1725 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1726 | |
| 1727 | std::string response_data; |
| 1728 | rv = ReadTransaction(&trans, &response_data); |
| 1729 | EXPECT_THAT(rv, IsOk()); |
| 1730 | EXPECT_EQ("hello world", response_data); |
| 1731 | } |
| 1732 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1733 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1734 | Check100ResponseTiming(false /* use_spdy */); |
| 1735 | } |
| 1736 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1737 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1738 | Check100ResponseTiming(true /* use_spdy */); |
| 1739 | } |
| 1740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1741 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1742 | HttpRequestInfo request; |
| 1743 | request.method = "POST"; |
| 1744 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1745 | request.traffic_annotation = |
| 1746 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1747 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1750 | |
| 1751 | MockRead data_reads[] = { |
| 1752 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1753 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1754 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1755 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1756 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1757 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1758 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1759 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1760 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1762 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1763 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1764 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1765 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1766 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1767 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1768 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1769 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1770 | } |
| 1771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1772 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1773 | HttpRequestInfo request; |
| 1774 | request.method = "POST"; |
| 1775 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1776 | request.traffic_annotation = |
| 1777 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1778 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1780 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1781 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1782 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1783 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1784 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1785 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1786 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1787 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1788 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1789 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1790 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1792 | |
| 1793 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1794 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1795 | } |
| 1796 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1797 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1798 | const MockWrite* write_failure, |
| 1799 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1800 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1801 | request.method = "GET"; |
| 1802 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1803 | request.traffic_annotation = |
| 1804 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1805 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 1806 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1807 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1809 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1810 | // Written data for successfully sending both requests. |
| 1811 | MockWrite data1_writes[] = { |
| 1812 | MockWrite("GET / HTTP/1.1\r\n" |
| 1813 | "Host: www.foo.com\r\n" |
| 1814 | "Connection: keep-alive\r\n\r\n"), |
| 1815 | MockWrite("GET / HTTP/1.1\r\n" |
| 1816 | "Host: www.foo.com\r\n" |
| 1817 | "Connection: keep-alive\r\n\r\n") |
| 1818 | }; |
| 1819 | |
| 1820 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1821 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1822 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1823 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1824 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1825 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1826 | |
| 1827 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1828 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1829 | data1_writes[1] = *write_failure; |
| 1830 | } else { |
| 1831 | ASSERT_TRUE(read_failure); |
| 1832 | data1_reads[2] = *read_failure; |
| 1833 | } |
| 1834 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1835 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1836 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1837 | |
| 1838 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1839 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1840 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1841 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1842 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1843 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1844 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1845 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1846 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1847 | "hello", "world" |
| 1848 | }; |
| 1849 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1850 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1851 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1852 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1853 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1858 | |
| 1859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1860 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1861 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1862 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1863 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1864 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1865 | if (i == 0) { |
| 1866 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1867 | } else { |
| 1868 | // The second request should be using a new socket. |
| 1869 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1870 | } |
| 1871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1872 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1873 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1874 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1875 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1876 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1877 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1878 | |
| 1879 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1880 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1881 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1882 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1883 | } |
| 1884 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1885 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1886 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1887 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1888 | const MockRead* read_failure, |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1889 | bool use_spdy, |
| 1890 | bool chunked_upload) { |
| 1891 | SpdyTestUtil spdy_util; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1892 | HttpRequestInfo request; |
| 1893 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1894 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1895 | request.traffic_annotation = |
| 1896 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1897 | |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1898 | const char upload_data[] = "foobar"; |
| 1899 | ChunkedUploadDataStream upload_data_stream(0); |
| 1900 | if (chunked_upload) { |
| 1901 | request.method = "POST"; |
| 1902 | upload_data_stream.AppendData(upload_data, base::size(upload_data) - 1, |
| 1903 | true); |
| 1904 | request.upload_data_stream = &upload_data_stream; |
| 1905 | } |
| 1906 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 1907 | RecordingTestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1908 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1910 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1911 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1912 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1913 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1914 | ssl1.next_proto = kProtoHTTP2; |
| 1915 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1916 | } |
| 1917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1918 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1919 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1920 | // SPDY versions of the request and response. |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1921 | |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 1922 | spdy::Http2HeaderBlock spdy_post_header_block; |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1923 | spdy_post_header_block[spdy::kHttp2MethodHeader] = "POST"; |
| 1924 | spdy_util.AddUrlToHeaderBlock(request.url.spec(), &spdy_post_header_block); |
| 1925 | spdy::SpdySerializedFrame spdy_request( |
| 1926 | chunked_upload |
| 1927 | ? spdy_util.ConstructSpdyHeaders(1, std::move(spdy_post_header_block), |
| 1928 | DEFAULT_PRIORITY, false) |
| 1929 | : spdy_util.ConstructSpdyGet(request.url.spec().c_str(), 1, |
| 1930 | DEFAULT_PRIORITY)); |
| 1931 | |
| 1932 | spdy::SpdySerializedFrame spdy_request_body( |
| 1933 | spdy_util.ConstructSpdyDataFrame(1, "foobar", true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1934 | spdy::SpdySerializedFrame spdy_response( |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1935 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1936 | spdy::SpdySerializedFrame spdy_data( |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1937 | spdy_util.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1938 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1939 | // HTTP/1.1 versions of the request and response. |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1940 | const std::string http_request = |
| 1941 | std::string(chunked_upload ? "POST" : "GET") + |
| 1942 | " / HTTP/1.1\r\n" |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1943 | "Host: www.foo.com\r\n" |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1944 | "Connection: keep-alive\r\n" + |
| 1945 | (chunked_upload ? "Transfer-Encoding: chunked\r\n\r\n" : "\r\n"); |
| 1946 | const char* kHttpRequest = http_request.c_str(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1947 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1948 | const char kHttpData[] = "hello"; |
| 1949 | |
| 1950 | std::vector<MockRead> data1_reads; |
| 1951 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1952 | if (write_failure) { |
| 1953 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1954 | data1_writes.push_back(*write_failure); |
| 1955 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1956 | } else { |
| 1957 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1958 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1959 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1960 | if (chunked_upload) |
| 1961 | data1_writes.push_back(CreateMockWrite(spdy_request_body)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1962 | } else { |
| 1963 | data1_writes.push_back(MockWrite(kHttpRequest)); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1964 | if (chunked_upload) { |
| 1965 | data1_writes.push_back(MockWrite("6\r\nfoobar\r\n")); |
| 1966 | data1_writes.push_back(MockWrite("0\r\n\r\n")); |
| 1967 | } |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1968 | } |
| 1969 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1970 | } |
| 1971 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1972 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1973 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1974 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1975 | std::vector<MockRead> data2_reads; |
| 1976 | std::vector<MockWrite> data2_writes; |
| 1977 | |
| 1978 | if (use_spdy) { |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1979 | int seq = 0; |
| 1980 | data2_writes.push_back(CreateMockWrite(spdy_request, seq++, ASYNC)); |
| 1981 | if (chunked_upload) |
| 1982 | data2_writes.push_back(CreateMockWrite(spdy_request_body, seq++, ASYNC)); |
| 1983 | data2_reads.push_back(CreateMockRead(spdy_response, seq++, ASYNC)); |
| 1984 | data2_reads.push_back(CreateMockRead(spdy_data, seq++, ASYNC)); |
| 1985 | data2_reads.push_back(MockRead(ASYNC, OK, seq++)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1986 | } else { |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1987 | int seq = 0; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1988 | data2_writes.push_back( |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1989 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), seq++)); |
| 1990 | if (chunked_upload) { |
| 1991 | data2_writes.push_back(MockWrite(ASYNC, "6\r\nfoobar\r\n", 11, seq++)); |
| 1992 | data2_writes.push_back(MockWrite(ASYNC, "0\r\n\r\n", 5, seq++)); |
| 1993 | } |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1994 | data2_reads.push_back( |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 1995 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), seq++)); |
| 1996 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), seq++)); |
| 1997 | data2_reads.push_back(MockRead(ASYNC, OK, seq++)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1998 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1999 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2000 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2001 | |
| 2002 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 2003 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2004 | // Wait for the preconnect to complete. |
| 2005 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 2006 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 2007 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2008 | |
| 2009 | // Make the request. |
| 2010 | TestCompletionCallback callback; |
| 2011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2012 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2013 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2014 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2016 | |
| 2017 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2018 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2019 | |
| 2020 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2021 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2022 | TestLoadTimingNotReused( |
| 2023 | load_timing_info, |
| 2024 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2026 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2027 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2028 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2029 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2030 | if (response->was_fetched_via_spdy) { |
| 2031 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 2032 | } else { |
| 2033 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2034 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2035 | |
| 2036 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2037 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2038 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2039 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2040 | } |
| 2041 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2042 | // 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] | 2043 | // ERR_HTTP2_PING_FAILED, ERR_HTTP2_SERVER_REFUSED_STREAM, |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2044 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 2045 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 2046 | HttpRequestInfo request; |
| 2047 | request.method = "GET"; |
| 2048 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2049 | request.traffic_annotation = |
| 2050 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2051 | |
| 2052 | // Check whether we give up after the third try. |
| 2053 | |
| 2054 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 2055 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2056 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 2057 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 2058 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2059 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 2060 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2061 | |
| 2062 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2063 | StaticSocketDataProvider data1(data_read1, data_write); |
| 2064 | StaticSocketDataProvider data2(data_read1, data_write); |
| 2065 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2066 | |
| 2067 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2068 | AddSSLSocketData(); |
| 2069 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2070 | AddSSLSocketData(); |
| 2071 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 2072 | AddSSLSocketData(); |
| 2073 | |
| 2074 | TestCompletionCallback callback; |
| 2075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2076 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2077 | |
| 2078 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 2079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2080 | |
| 2081 | rv = callback.WaitForResult(); |
Bence Béky | d0d6950 | 2019-06-25 19:47:18 | [diff] [blame] | 2082 | EXPECT_THAT(rv, IsError(ERR_HTTP2_SERVER_REFUSED_STREAM)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 2086 | HttpRequestInfo request; |
| 2087 | request.method = "GET"; |
| 2088 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2089 | request.traffic_annotation = |
| 2090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2091 | |
| 2092 | // Check whether we try atleast thrice before giving up. |
| 2093 | |
| 2094 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 2095 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2096 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 2097 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 2098 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2099 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 2100 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2101 | |
| 2102 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 2103 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2104 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 2105 | spdy::SpdySerializedFrame spdy_data( |
| 2106 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2107 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 2108 | CreateMockRead(spdy_data, 2)}; |
| 2109 | |
| 2110 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2111 | StaticSocketDataProvider data1(data_read1, data_write); |
| 2112 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2113 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2114 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 2115 | |
| 2116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2117 | AddSSLSocketData(); |
| 2118 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2119 | AddSSLSocketData(); |
| 2120 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 2121 | AddSSLSocketData(); |
| 2122 | |
| 2123 | TestCompletionCallback callback; |
| 2124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2125 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2126 | |
| 2127 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 2128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 2129 | |
| 2130 | rv = callback.WaitForResult(); |
| 2131 | EXPECT_THAT(rv, IsOk()); |
| 2132 | } |
| 2133 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2134 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2135 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2136 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 2137 | } |
| 2138 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2139 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2140 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2141 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2142 | } |
| 2143 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2144 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2145 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2146 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2147 | } |
| 2148 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2149 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2150 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2151 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2152 | MockRead read_failure(SYNCHRONOUS, |
| 2153 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2154 | "Connection: Keep-Alive\r\n" |
| 2155 | "Content-Length: 6\r\n\r\n" |
| 2156 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2157 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2158 | } |
| 2159 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2160 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2161 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2162 | PreconnectErrorResendRequestTest(&write_failure, nullptr, |
| 2163 | false /* use_spdy */); |
| 2164 | PreconnectErrorResendRequestTest( |
| 2165 | &write_failure, nullptr, false /* use_spdy */, true /* chunked_upload */); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2166 | } |
| 2167 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2168 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2169 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2170 | PreconnectErrorResendRequestTest(nullptr, &read_failure, |
| 2171 | false /* use_spdy */); |
| 2172 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false /* use_spdy */, |
| 2173 | true /* chunked_upload */); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2174 | } |
| 2175 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2176 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2177 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2178 | PreconnectErrorResendRequestTest(nullptr, &read_failure, |
| 2179 | false /* use_spdy */); |
| 2180 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false /* use_spdy */, |
| 2181 | true /* chunked_upload */); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2182 | } |
| 2183 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2184 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2185 | MockRead read_failure(ASYNC, OK); // EOF |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2186 | PreconnectErrorResendRequestTest(nullptr, &read_failure, |
| 2187 | false /* use_spdy */); |
| 2188 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false /* use_spdy */, |
| 2189 | true /* chunked_upload */); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2190 | } |
| 2191 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2192 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2193 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2194 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2195 | MockRead read_failure(SYNCHRONOUS, |
| 2196 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2197 | "Connection: Keep-Alive\r\n" |
| 2198 | "Content-Length: 6\r\n\r\n" |
| 2199 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2200 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2201 | PreconnectErrorResendRequestTest(nullptr, &read_failure, |
| 2202 | false /* use_spdy */); |
| 2203 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false /* use_spdy */, |
| 2204 | true /* chunked_upload */); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2205 | } |
| 2206 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2207 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2208 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2209 | PreconnectErrorResendRequestTest(&write_failure, nullptr, |
| 2210 | true /* use_spdy */); |
| 2211 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true /* use_spdy */, |
| 2212 | true /* chunked_upload */); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2213 | } |
| 2214 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2215 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2216 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2217 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true /* use_spdy */); |
| 2218 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true /* use_spdy */, |
| 2219 | true /* chunked_upload */); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2220 | } |
| 2221 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2222 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2223 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2224 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true /* use_spdy */); |
| 2225 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true /* use_spdy */, |
| 2226 | true /* chunked_upload */); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2227 | } |
| 2228 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2229 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2230 | MockRead read_failure(ASYNC, OK); // EOF |
Yoichi Osato | f17bc89 | 2020-08-05 01:49:04 | [diff] [blame] | 2231 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true /* use_spdy */); |
| 2232 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true /* use_spdy */, |
| 2233 | true /* chunked_upload */); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2234 | } |
| 2235 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2236 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2237 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2238 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2239 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2240 | request.traffic_annotation = |
| 2241 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2245 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2246 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2247 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2248 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2249 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2250 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2251 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2252 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2253 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2255 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2256 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2257 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2258 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2259 | |
| 2260 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2261 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2262 | |
| 2263 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2264 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2265 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | // What do various browsers do when the server closes a non-keepalive |
| 2269 | // connection without sending any response header or body? |
| 2270 | // |
| 2271 | // IE7: error page |
| 2272 | // Safari 3.1.2 (Windows): error page |
| 2273 | // Firefox 3.0.1: blank page |
| 2274 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2275 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2276 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2277 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2278 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2279 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2280 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2281 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2282 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2283 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2284 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2285 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2286 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2287 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2288 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2289 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2290 | // destructor in such situations. |
| 2291 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2292 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2293 | HttpRequestInfo request; |
| 2294 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2295 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2296 | request.traffic_annotation = |
| 2297 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2298 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2300 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2301 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2302 | |
| 2303 | MockRead data_reads[] = { |
| 2304 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2305 | MockRead("Connection: keep-alive\r\n"), |
| 2306 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2307 | MockRead("hello"), |
| 2308 | MockRead(SYNCHRONOUS, 0), |
| 2309 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2310 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2311 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2312 | |
| 2313 | TestCompletionCallback callback; |
| 2314 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2315 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2317 | |
| 2318 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2319 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2320 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2321 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2322 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2323 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2324 | if (rv == ERR_IO_PENDING) |
| 2325 | rv = callback.WaitForResult(); |
| 2326 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2327 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2328 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2329 | |
| 2330 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2331 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2332 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2333 | } |
| 2334 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2335 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2336 | HttpRequestInfo request; |
| 2337 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2338 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2339 | request.traffic_annotation = |
| 2340 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2341 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2343 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2344 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2345 | |
| 2346 | MockRead data_reads[] = { |
| 2347 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2348 | MockRead("Connection: keep-alive\r\n"), |
| 2349 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2350 | MockRead(SYNCHRONOUS, 0), |
| 2351 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2352 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2354 | |
| 2355 | TestCompletionCallback callback; |
| 2356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2357 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2359 | |
| 2360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2361 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2362 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2363 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2364 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2365 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2366 | if (rv == ERR_IO_PENDING) |
| 2367 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2368 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2369 | |
| 2370 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2371 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2372 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2373 | } |
| 2374 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2375 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2376 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2377 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2378 | HttpRequestInfo request; |
| 2379 | request.method = "GET"; |
| 2380 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2381 | request.traffic_annotation = |
| 2382 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2383 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2384 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2385 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2386 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2387 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2388 | const char* request_data = |
| 2389 | "GET / HTTP/1.1\r\n" |
| 2390 | "Host: www.foo.com\r\n" |
| 2391 | "Connection: keep-alive\r\n\r\n"; |
| 2392 | MockWrite data_writes[] = { |
| 2393 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2394 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2395 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2396 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2397 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2398 | }; |
| 2399 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2400 | // Note that because all these reads happen in the same |
| 2401 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2402 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2403 | MockRead data_reads[] = { |
| 2404 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2405 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2406 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2407 | MockRead(ASYNC, 7, |
| 2408 | "HTTP/1.1 302 Found\r\n" |
| 2409 | "Content-Length: 0\r\n\r\n"), |
| 2410 | MockRead(ASYNC, 9, |
| 2411 | "HTTP/1.1 302 Found\r\n" |
| 2412 | "Content-Length: 5\r\n\r\n" |
| 2413 | "hello"), |
| 2414 | MockRead(ASYNC, 11, |
| 2415 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2416 | "Content-Length: 0\r\n\r\n"), |
| 2417 | MockRead(ASYNC, 13, |
| 2418 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2419 | "Content-Length: 5\r\n\r\n" |
| 2420 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2421 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2422 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2423 | // the set_busy_before_sync_reads(true) call, while the |
| 2424 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2425 | // reuseable. See http://crbug.com/544255. |
| 2426 | MockRead(ASYNC, 15, |
| 2427 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2428 | "Content-Length: 5\r\n\r\n"), |
| 2429 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2430 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2431 | MockRead(ASYNC, 18, |
| 2432 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2433 | "Content-Length: 5\r\n\r\n" |
| 2434 | "he"), |
| 2435 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2436 | |
| 2437 | // The body of the final request is actually read. |
| 2438 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2439 | MockRead(ASYNC, 22, "hello"), |
| 2440 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2441 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2442 | data.set_busy_before_sync_reads(true); |
| 2443 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2444 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2445 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2446 | std::string response_lines[kNumUnreadBodies]; |
| 2447 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2448 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2449 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2450 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2451 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2452 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2453 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2455 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2456 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2457 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2458 | LoadTimingInfo load_timing_info; |
| 2459 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2460 | if (i == 0) { |
| 2461 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2462 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2463 | } else { |
| 2464 | TestLoadTimingReused(load_timing_info); |
| 2465 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2466 | } |
| 2467 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2468 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2469 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2470 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2471 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2472 | response_lines[i] = response->headers->GetStatusLine(); |
| 2473 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2474 | // Delete the transaction without reading the response bodies. Then spin |
| 2475 | // the message loop, so the response bodies are drained. |
| 2476 | trans.reset(); |
| 2477 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2478 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2479 | |
| 2480 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2481 | "HTTP/1.1 204 No Content", |
| 2482 | "HTTP/1.1 205 Reset Content", |
| 2483 | "HTTP/1.1 304 Not Modified", |
| 2484 | "HTTP/1.1 302 Found", |
| 2485 | "HTTP/1.1 302 Found", |
| 2486 | "HTTP/1.1 301 Moved Permanently", |
| 2487 | "HTTP/1.1 301 Moved Permanently", |
| 2488 | "HTTP/1.1 200 Hunky-Dory", |
| 2489 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2490 | }; |
| 2491 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2492 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2493 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2494 | |
| 2495 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2496 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2498 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2500 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2501 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2502 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2503 | ASSERT_TRUE(response); |
| 2504 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2505 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2506 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2507 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2508 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2509 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2510 | } |
| 2511 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2512 | // Sockets that receive extra data after a response is complete should not be |
| 2513 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2514 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2516 | MockWrite data_writes1[] = { |
| 2517 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2518 | "Host: www.borked.com\r\n" |
| 2519 | "Connection: keep-alive\r\n\r\n"), |
| 2520 | }; |
| 2521 | |
| 2522 | MockRead data_reads1[] = { |
| 2523 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2524 | "Connection: keep-alive\r\n" |
| 2525 | "Content-Length: 22\r\n\r\n" |
| 2526 | "This server is borked."), |
| 2527 | }; |
| 2528 | |
| 2529 | MockWrite data_writes2[] = { |
| 2530 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2531 | "Host: www.borked.com\r\n" |
| 2532 | "Connection: keep-alive\r\n\r\n"), |
| 2533 | }; |
| 2534 | |
| 2535 | MockRead data_reads2[] = { |
| 2536 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2537 | "Content-Length: 3\r\n\r\n" |
| 2538 | "foo"), |
| 2539 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2540 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2542 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2543 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2544 | |
| 2545 | TestCompletionCallback callback; |
| 2546 | HttpRequestInfo request1; |
| 2547 | request1.method = "HEAD"; |
| 2548 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2549 | request1.traffic_annotation = |
| 2550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2551 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2552 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2553 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2554 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2555 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2556 | |
| 2557 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2558 | ASSERT_TRUE(response1); |
| 2559 | ASSERT_TRUE(response1->headers); |
| 2560 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2561 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2562 | |
| 2563 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2564 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2565 | EXPECT_EQ("", response_data1); |
| 2566 | // Deleting the transaction attempts to release the socket back into the |
| 2567 | // socket pool. |
| 2568 | trans1.reset(); |
| 2569 | |
| 2570 | HttpRequestInfo request2; |
| 2571 | request2.method = "GET"; |
| 2572 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2573 | request2.traffic_annotation = |
| 2574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2575 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2576 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2577 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2578 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2579 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2580 | |
| 2581 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2582 | ASSERT_TRUE(response2); |
| 2583 | ASSERT_TRUE(response2->headers); |
| 2584 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2585 | |
| 2586 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2587 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2588 | EXPECT_EQ("foo", response_data2); |
| 2589 | } |
| 2590 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2591 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2593 | MockWrite data_writes1[] = { |
| 2594 | MockWrite("GET / HTTP/1.1\r\n" |
| 2595 | "Host: www.borked.com\r\n" |
| 2596 | "Connection: keep-alive\r\n\r\n"), |
| 2597 | }; |
| 2598 | |
| 2599 | MockRead data_reads1[] = { |
| 2600 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2601 | "Connection: keep-alive\r\n" |
| 2602 | "Content-Length: 22\r\n\r\n" |
| 2603 | "This server is borked." |
| 2604 | "Bonus data!"), |
| 2605 | }; |
| 2606 | |
| 2607 | MockWrite data_writes2[] = { |
| 2608 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2609 | "Host: www.borked.com\r\n" |
| 2610 | "Connection: keep-alive\r\n\r\n"), |
| 2611 | }; |
| 2612 | |
| 2613 | MockRead data_reads2[] = { |
| 2614 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2615 | "Content-Length: 3\r\n\r\n" |
| 2616 | "foo"), |
| 2617 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2618 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2619 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2620 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2621 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2622 | |
| 2623 | TestCompletionCallback callback; |
| 2624 | HttpRequestInfo request1; |
| 2625 | request1.method = "GET"; |
| 2626 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2627 | request1.traffic_annotation = |
| 2628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2629 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2630 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2631 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2632 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2633 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2634 | |
| 2635 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2636 | ASSERT_TRUE(response1); |
| 2637 | ASSERT_TRUE(response1->headers); |
| 2638 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2639 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2640 | |
| 2641 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2642 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2643 | EXPECT_EQ("This server is borked.", response_data1); |
| 2644 | // Deleting the transaction attempts to release the socket back into the |
| 2645 | // socket pool. |
| 2646 | trans1.reset(); |
| 2647 | |
| 2648 | HttpRequestInfo request2; |
| 2649 | request2.method = "GET"; |
| 2650 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2651 | request2.traffic_annotation = |
| 2652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2653 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2654 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2655 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2656 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2657 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2658 | |
| 2659 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2660 | ASSERT_TRUE(response2); |
| 2661 | ASSERT_TRUE(response2->headers); |
| 2662 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2663 | |
| 2664 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2665 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2666 | EXPECT_EQ("foo", response_data2); |
| 2667 | } |
| 2668 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2669 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2671 | MockWrite data_writes1[] = { |
| 2672 | MockWrite("GET / HTTP/1.1\r\n" |
| 2673 | "Host: www.borked.com\r\n" |
| 2674 | "Connection: keep-alive\r\n\r\n"), |
| 2675 | }; |
| 2676 | |
| 2677 | MockRead data_reads1[] = { |
| 2678 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2679 | "Connection: keep-alive\r\n" |
| 2680 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2681 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2682 | MockRead("0\r\n\r\nBonus data!"), |
| 2683 | }; |
| 2684 | |
| 2685 | MockWrite data_writes2[] = { |
| 2686 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2687 | "Host: www.borked.com\r\n" |
| 2688 | "Connection: keep-alive\r\n\r\n"), |
| 2689 | }; |
| 2690 | |
| 2691 | MockRead data_reads2[] = { |
| 2692 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2693 | "Content-Length: 3\r\n\r\n" |
| 2694 | "foo"), |
| 2695 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2696 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2697 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2698 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2699 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2700 | |
| 2701 | TestCompletionCallback callback; |
| 2702 | HttpRequestInfo request1; |
| 2703 | request1.method = "GET"; |
| 2704 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2705 | request1.traffic_annotation = |
| 2706 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2707 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2708 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2709 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2710 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2711 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2712 | |
| 2713 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2714 | ASSERT_TRUE(response1); |
| 2715 | ASSERT_TRUE(response1->headers); |
| 2716 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2717 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2718 | |
| 2719 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2720 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2721 | EXPECT_EQ("This server is borked.", response_data1); |
| 2722 | // Deleting the transaction attempts to release the socket back into the |
| 2723 | // socket pool. |
| 2724 | trans1.reset(); |
| 2725 | |
| 2726 | HttpRequestInfo request2; |
| 2727 | request2.method = "GET"; |
| 2728 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2729 | request2.traffic_annotation = |
| 2730 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2731 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2732 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2733 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2734 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2735 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2736 | |
| 2737 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2738 | ASSERT_TRUE(response2); |
| 2739 | ASSERT_TRUE(response2->headers); |
| 2740 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2741 | |
| 2742 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2743 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2744 | EXPECT_EQ("foo", response_data2); |
| 2745 | } |
| 2746 | |
| 2747 | // This is a little different from the others - it tests the case that the |
| 2748 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2749 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2750 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2751 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2753 | MockWrite data_writes1[] = { |
| 2754 | MockWrite("GET / HTTP/1.1\r\n" |
| 2755 | "Host: www.borked.com\r\n" |
| 2756 | "Connection: keep-alive\r\n\r\n"), |
| 2757 | }; |
| 2758 | |
| 2759 | MockRead data_reads1[] = { |
| 2760 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2761 | "Connection: keep-alive\r\n" |
| 2762 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2763 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2764 | MockRead("0\r\n\r\nBonus data!"), |
| 2765 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2766 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2767 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2768 | |
| 2769 | TestCompletionCallback callback; |
| 2770 | HttpRequestInfo request1; |
| 2771 | request1.method = "GET"; |
| 2772 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2773 | request1.traffic_annotation = |
| 2774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2775 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2776 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2777 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2778 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2779 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2780 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2781 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2782 | ASSERT_TRUE(response1); |
| 2783 | ASSERT_TRUE(response1->headers); |
| 2784 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2785 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2786 | |
| 2787 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2788 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2789 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2790 | |
| 2791 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2792 | // socket can't be reused, rather than returning it to the socket pool. |
| 2793 | base::RunLoop().RunUntilIdle(); |
| 2794 | |
| 2795 | // There should be no idle sockets in the pool. |
| 2796 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2797 | } |
| 2798 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2799 | // Test the request-challenge-retry sequence for basic auth. |
| 2800 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2801 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2802 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2804 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2805 | request.traffic_annotation = |
| 2806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2807 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2808 | RecordingTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2809 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2812 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2813 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2814 | MockWrite( |
| 2815 | "GET / HTTP/1.1\r\n" |
| 2816 | "Host: www.example.org\r\n" |
| 2817 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2818 | }; |
| 2819 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2820 | MockRead data_reads1[] = { |
| 2821 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2822 | // Give a couple authenticate options (only the middle one is actually |
| 2823 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2824 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2825 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2826 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2827 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2828 | // Large content-length -- won't matter, as connection will be reset. |
| 2829 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2830 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2831 | }; |
| 2832 | |
| 2833 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2834 | // be issuing -- the final header line contains the credentials. |
| 2835 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2836 | MockWrite( |
| 2837 | "GET / HTTP/1.1\r\n" |
| 2838 | "Host: www.example.org\r\n" |
| 2839 | "Connection: keep-alive\r\n" |
| 2840 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2841 | }; |
| 2842 | |
| 2843 | // Lastly, the server responds with the actual content. |
| 2844 | MockRead data_reads2[] = { |
| 2845 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2846 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2847 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2848 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2849 | }; |
| 2850 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2851 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2852 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2853 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2854 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2855 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2856 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2857 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2858 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2859 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2860 | |
| 2861 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2862 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2863 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2864 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2865 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2866 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2867 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2868 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2869 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2870 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2871 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2873 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2874 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2875 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2877 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2879 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2881 | |
| 2882 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2883 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2884 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2885 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2886 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2887 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2888 | // The load timing after restart should have a new socket ID, and times after |
| 2889 | // those of the first load timing. |
| 2890 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2891 | load_timing_info2.connect_timing.connect_start); |
| 2892 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2894 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2895 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2896 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2897 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2899 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2900 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2901 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2902 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2903 | } |
| 2904 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2905 | // Test the request-challenge-retry sequence for basic auth. |
| 2906 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2907 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2908 | HttpRequestInfo request; |
| 2909 | request.method = "GET"; |
| 2910 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2911 | request.traffic_annotation = |
| 2912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2913 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 2914 | RecordingTestNetLog log; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2915 | MockHostResolver* resolver = new MockHostResolver(); |
| 2916 | session_deps_.net_log = &log; |
| 2917 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2918 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2919 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2920 | |
| 2921 | resolver->rules()->ClearRules(); |
| 2922 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2923 | |
| 2924 | MockWrite data_writes1[] = { |
| 2925 | MockWrite("GET / HTTP/1.1\r\n" |
| 2926 | "Host: www.example.org\r\n" |
| 2927 | "Connection: keep-alive\r\n\r\n"), |
| 2928 | }; |
| 2929 | |
| 2930 | MockRead data_reads1[] = { |
| 2931 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2932 | // Give a couple authenticate options (only the middle one is actually |
| 2933 | // supported). |
| 2934 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2935 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2936 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2937 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2938 | // Large content-length -- won't matter, as connection will be reset. |
| 2939 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2940 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2941 | }; |
| 2942 | |
| 2943 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2944 | // be issuing -- the final header line contains the credentials. |
| 2945 | MockWrite data_writes2[] = { |
| 2946 | MockWrite("GET / HTTP/1.1\r\n" |
| 2947 | "Host: www.example.org\r\n" |
| 2948 | "Connection: keep-alive\r\n" |
| 2949 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2950 | }; |
| 2951 | |
| 2952 | // Lastly, the server responds with the actual content. |
| 2953 | MockRead data_reads2[] = { |
| 2954 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2955 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2956 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2957 | }; |
| 2958 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2959 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2960 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2961 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2962 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2963 | |
| 2964 | TestCompletionCallback callback1; |
| 2965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2966 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2967 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2968 | |
| 2969 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2970 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2971 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2972 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2973 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2974 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2975 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2976 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2978 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2979 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2980 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2981 | |
| 2982 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2983 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2984 | ASSERT_FALSE(endpoint.address().empty()); |
| 2985 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2986 | |
| 2987 | resolver->rules()->ClearRules(); |
| 2988 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2989 | |
| 2990 | TestCompletionCallback callback2; |
| 2991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2992 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2993 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2994 | |
| 2995 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2996 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2997 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2998 | // The load timing after restart should have a new socket ID, and times after |
| 2999 | // those of the first load timing. |
| 3000 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3001 | load_timing_info2.connect_timing.connect_start); |
| 3002 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3003 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3004 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3005 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3006 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3007 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 3008 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3009 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 3010 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3011 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 3012 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 3013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3014 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 3015 | ASSERT_FALSE(endpoint.address().empty()); |
| 3016 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 3017 | } |
| 3018 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 3019 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 3020 | // will eventually give up. |
| 3021 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 3022 | HttpRequestInfo request; |
| 3023 | request.method = "GET"; |
| 3024 | request.url = GURL("http://www.example.org/"); |
| 3025 | request.traffic_annotation = |
| 3026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3027 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3028 | RecordingTestNetLog log; |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 3029 | session_deps_.net_log = &log; |
| 3030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3031 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 3032 | |
| 3033 | MockWrite data_writes[] = { |
| 3034 | MockWrite("GET / HTTP/1.1\r\n" |
| 3035 | "Host: www.example.org\r\n" |
| 3036 | "Connection: keep-alive\r\n\r\n"), |
| 3037 | }; |
| 3038 | |
| 3039 | MockRead data_reads[] = { |
| 3040 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 3041 | // Give a couple authenticate options (only the middle one is actually |
| 3042 | // supported). |
| 3043 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 3044 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3045 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 3046 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3047 | // Large content-length -- won't matter, as connection will be reset. |
| 3048 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 3049 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 3050 | }; |
| 3051 | |
| 3052 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3053 | // be issuing -- the final header line contains the credentials. |
| 3054 | MockWrite data_writes_restart[] = { |
| 3055 | MockWrite("GET / HTTP/1.1\r\n" |
| 3056 | "Host: www.example.org\r\n" |
| 3057 | "Connection: keep-alive\r\n" |
| 3058 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3059 | }; |
| 3060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3061 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 3062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3063 | |
| 3064 | TestCompletionCallback callback; |
| 3065 | int rv = callback.GetResult( |
| 3066 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 3067 | |
| 3068 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 3069 | for (int i = 0; i < 32; i++) { |
| 3070 | // Check the previous response was a 401. |
| 3071 | EXPECT_THAT(rv, IsOk()); |
| 3072 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 3073 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3074 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 3075 | |
| 3076 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3077 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 3078 | session_deps_.socket_factory->AddSocketDataProvider( |
| 3079 | data_restarts.back().get()); |
| 3080 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3081 | callback.callback())); |
| 3082 | } |
| 3083 | |
| 3084 | // After too many tries, the transaction should have given up. |
| 3085 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 3086 | } |
| 3087 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3088 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3089 | HttpRequestInfo request; |
| 3090 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3091 | request.url = GURL("http://www.example.org/"); |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 3092 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3093 | request.traffic_annotation = |
| 3094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3095 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3096 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3097 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3098 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3099 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3100 | MockWrite( |
| 3101 | "GET / HTTP/1.1\r\n" |
| 3102 | "Host: www.example.org\r\n" |
| 3103 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3104 | }; |
| 3105 | |
| 3106 | MockRead data_reads[] = { |
| 3107 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 3108 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3109 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3110 | // Large content-length -- won't matter, as connection will be reset. |
| 3111 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3112 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3113 | }; |
| 3114 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3115 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3116 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3117 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3118 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3119 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3121 | |
| 3122 | rv = callback.WaitForResult(); |
| 3123 | EXPECT_EQ(0, rv); |
| 3124 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3125 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3126 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3127 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3128 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 3129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3130 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3131 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3132 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 3133 | } |
| 3134 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3135 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3136 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3137 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3138 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3139 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3140 | // reused. See http://crbug.com/544255. |
| 3141 | for (int i = 0; i < 2; ++i) { |
| 3142 | HttpRequestInfo request; |
| 3143 | request.method = "GET"; |
| 3144 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3145 | request.traffic_annotation = |
| 3146 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3147 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3148 | RecordingTestNetLog log; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3149 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3151 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3152 | MockWrite data_writes[] = { |
| 3153 | MockWrite(ASYNC, 0, |
| 3154 | "GET / HTTP/1.1\r\n" |
| 3155 | "Host: www.example.org\r\n" |
| 3156 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3158 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3159 | // be issuing -- the final header line contains the credentials. |
| 3160 | MockWrite(ASYNC, 6, |
| 3161 | "GET / HTTP/1.1\r\n" |
| 3162 | "Host: www.example.org\r\n" |
| 3163 | "Connection: keep-alive\r\n" |
| 3164 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3165 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3166 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3167 | MockRead data_reads[] = { |
| 3168 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 3169 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3170 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3171 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 3172 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3173 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3174 | // Lastly, the server responds with the actual content. |
| 3175 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 3176 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3177 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 3178 | MockRead(ASYNC, 10, "Hello"), |
| 3179 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3180 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3181 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3182 | data.set_busy_before_sync_reads(true); |
| 3183 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3184 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3185 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3187 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3188 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3189 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3190 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3191 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3192 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3193 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3195 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3196 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3197 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3198 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3199 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3201 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3202 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3203 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3204 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3205 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3206 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3207 | TestLoadTimingReused(load_timing_info2); |
| 3208 | // The load timing after restart should have the same socket ID, and times |
| 3209 | // those of the first load timing. |
| 3210 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3211 | load_timing_info2.send_start); |
| 3212 | 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] | 3213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3214 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3215 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3216 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3217 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3218 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3219 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3220 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3221 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3222 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3223 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3224 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3225 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3226 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3230 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3231 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3232 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3233 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3234 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3235 | request.traffic_annotation = |
| 3236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3237 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3239 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3240 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3241 | MockWrite("GET / HTTP/1.1\r\n" |
| 3242 | "Host: www.example.org\r\n" |
| 3243 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3245 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3246 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3247 | MockWrite("GET / HTTP/1.1\r\n" |
| 3248 | "Host: www.example.org\r\n" |
| 3249 | "Connection: keep-alive\r\n" |
| 3250 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3251 | }; |
| 3252 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3253 | MockRead data_reads1[] = { |
| 3254 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3255 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3256 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3257 | |
| 3258 | // Lastly, the server responds with the actual content. |
| 3259 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3260 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3261 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3262 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3263 | }; |
| 3264 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3265 | // An incorrect reconnect would cause this to be read. |
| 3266 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3267 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3268 | }; |
| 3269 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3270 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3271 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3272 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3273 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3275 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3278 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3280 | |
| 3281 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3284 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3285 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3286 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3288 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3290 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3292 | |
| 3293 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3294 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3296 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3297 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3298 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3299 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3303 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3304 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3305 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3307 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3308 | request.traffic_annotation = |
| 3309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3310 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3312 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3313 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3314 | MockWrite("GET / HTTP/1.1\r\n" |
| 3315 | "Host: www.example.org\r\n" |
| 3316 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3317 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3318 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3319 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3320 | MockWrite("GET / HTTP/1.1\r\n" |
| 3321 | "Host: www.example.org\r\n" |
| 3322 | "Connection: keep-alive\r\n" |
| 3323 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3324 | }; |
| 3325 | |
| 3326 | // Respond with 5 kb of response body. |
| 3327 | std::string large_body_string("Unauthorized"); |
| 3328 | large_body_string.append(5 * 1024, ' '); |
| 3329 | large_body_string.append("\r\n"); |
| 3330 | |
| 3331 | MockRead data_reads1[] = { |
| 3332 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3333 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3334 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3335 | // 5134 = 12 + 5 * 1024 + 2 |
| 3336 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3337 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3338 | |
| 3339 | // Lastly, the server responds with the actual content. |
| 3340 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3341 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3342 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3343 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3344 | }; |
| 3345 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3346 | // An incorrect reconnect would cause this to be read. |
| 3347 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3348 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3349 | }; |
| 3350 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3351 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3352 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3353 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3354 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3356 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3358 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3359 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3361 | |
| 3362 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3365 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3366 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3367 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3369 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3371 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3373 | |
| 3374 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3377 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3378 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3379 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3380 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3384 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3385 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3386 | HttpRequestInfo request; |
| 3387 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3388 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3389 | request.traffic_annotation = |
| 3390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3393 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3394 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3395 | MockWrite( |
| 3396 | "GET / HTTP/1.1\r\n" |
| 3397 | "Host: www.example.org\r\n" |
| 3398 | "Connection: keep-alive\r\n\r\n"), |
| 3399 | // This simulates the seemingly successful write to a closed connection |
| 3400 | // if the bug is not fixed. |
| 3401 | MockWrite( |
| 3402 | "GET / HTTP/1.1\r\n" |
| 3403 | "Host: www.example.org\r\n" |
| 3404 | "Connection: keep-alive\r\n" |
| 3405 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3406 | }; |
| 3407 | |
| 3408 | MockRead data_reads1[] = { |
| 3409 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3410 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3411 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3412 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3413 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3414 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3415 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3416 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3417 | }; |
| 3418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3419 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3420 | // be issuing -- the final header line contains the credentials. |
| 3421 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3422 | MockWrite( |
| 3423 | "GET / HTTP/1.1\r\n" |
| 3424 | "Host: www.example.org\r\n" |
| 3425 | "Connection: keep-alive\r\n" |
| 3426 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3427 | }; |
| 3428 | |
| 3429 | // Lastly, the server responds with the actual content. |
| 3430 | MockRead data_reads2[] = { |
| 3431 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3432 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3433 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3434 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3435 | }; |
| 3436 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3437 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3438 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3439 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3440 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3442 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3444 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3445 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3447 | |
| 3448 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3449 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3450 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3451 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3452 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3453 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3455 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3456 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3457 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3459 | |
| 3460 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3461 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3462 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3463 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3464 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3465 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3466 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3467 | } |
| 3468 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3469 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3470 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3471 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3472 | HttpRequestInfo request; |
| 3473 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3474 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3475 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 3476 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3477 | request.traffic_annotation = |
| 3478 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3479 | |
| 3480 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3481 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3482 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3483 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3484 | RecordingBoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3485 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3487 | |
| 3488 | // Since we have proxy, should try to establish tunnel. |
| 3489 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3490 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3491 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3492 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3493 | }; |
| 3494 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3495 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3496 | // connection. |
| 3497 | MockRead data_reads1[] = { |
| 3498 | // No credentials. |
| 3499 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3500 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3501 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3502 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3503 | // Since the first connection couldn't be reused, need to establish another |
| 3504 | // once given credentials. |
| 3505 | MockWrite data_writes2[] = { |
| 3506 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3507 | // be issuing -- the final header line contains the credentials. |
| 3508 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3509 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3510 | "Proxy-Connection: keep-alive\r\n" |
| 3511 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3512 | |
| 3513 | MockWrite("GET / HTTP/1.1\r\n" |
| 3514 | "Host: www.example.org\r\n" |
| 3515 | "Connection: keep-alive\r\n\r\n"), |
| 3516 | }; |
| 3517 | |
| 3518 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3519 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3520 | |
| 3521 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3522 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3523 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3524 | MockRead(SYNCHRONOUS, "hello"), |
| 3525 | }; |
| 3526 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3527 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3528 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3529 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3530 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3531 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3533 | |
| 3534 | TestCompletionCallback callback1; |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3535 | ConnectedHandler connected_handler; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3536 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3537 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3538 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3539 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3540 | trans->SetConnectedCallback(connected_handler.Callback()); |
| 3541 | |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3542 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3544 | |
| 3545 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3546 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3547 | auto entries = log.GetEntries(); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3548 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3549 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3550 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3551 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3552 | entries, pos, |
| 3553 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3554 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3555 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3556 | // TODO(crbug.com/986744): Fix handling of OnConnected() when proxy |
| 3557 | // authentication is required. We should notify the callback that a connection |
| 3558 | // was established, even though the stream might not be ready for us to send |
| 3559 | // data through it. |
| 3560 | EXPECT_THAT(connected_handler.transports(), IsEmpty()); |
| 3561 | |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3562 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3563 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3564 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3565 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3566 | EXPECT_EQ(407, response->headers->response_code()); |
| 3567 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3568 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3569 | |
| 3570 | LoadTimingInfo load_timing_info; |
| 3571 | // CONNECT requests and responses are handled at the connect job level, so |
| 3572 | // the transaction does not yet have a connection. |
| 3573 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3574 | |
| 3575 | TestCompletionCallback callback2; |
| 3576 | |
| 3577 | rv = |
| 3578 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3579 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3580 | |
| 3581 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3582 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3583 | |
| 3584 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3585 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3586 | |
| 3587 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3588 | EXPECT_EQ(200, response->headers->response_code()); |
| 3589 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3590 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3591 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3592 | TransportInfo expected_transport; |
| 3593 | expected_transport.type = TransportType::kProxied; |
| 3594 | expected_transport.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 70); |
| 3595 | EXPECT_THAT(connected_handler.transports(), ElementsAre(expected_transport)); |
| 3596 | |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 3597 | // Check that credentials were successfully cached, with the right target. |
| 3598 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 3599 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 3600 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey()); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 3601 | ASSERT_TRUE(entry); |
| 3602 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 3603 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 3604 | |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3605 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3606 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3607 | |
| 3608 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3609 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3610 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3611 | |
| 3612 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3613 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3617 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3618 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3619 | HttpRequestInfo request; |
| 3620 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3621 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3622 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 3623 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3624 | request.traffic_annotation = |
| 3625 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3626 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3627 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3628 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3629 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3630 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3631 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3632 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3634 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3635 | // Since we have proxy, should try to establish tunnel. |
| 3636 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3637 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3638 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3639 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3640 | }; |
| 3641 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3642 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3643 | // connection. |
| 3644 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3645 | // No credentials. |
| 3646 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3647 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3648 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3649 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3650 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3651 | MockWrite data_writes2[] = { |
| 3652 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3653 | // be issuing -- the final header line contains the credentials. |
| 3654 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3655 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3656 | "Proxy-Connection: keep-alive\r\n" |
| 3657 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3658 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3659 | MockWrite("GET / HTTP/1.1\r\n" |
| 3660 | "Host: www.example.org\r\n" |
| 3661 | "Connection: keep-alive\r\n\r\n"), |
| 3662 | }; |
| 3663 | |
| 3664 | MockRead data_reads2[] = { |
| 3665 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3666 | |
| 3667 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3668 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3669 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3670 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3671 | }; |
| 3672 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3673 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3674 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3675 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3676 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3677 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3679 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3680 | ConnectedHandler connected_handler; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3681 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3682 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3683 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3684 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3685 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3686 | trans->SetConnectedCallback(connected_handler.Callback()); |
| 3687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3688 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3690 | |
| 3691 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3692 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3693 | auto entries = log.GetEntries(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3694 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3695 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3696 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3697 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3698 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3699 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3700 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3701 | |
| 3702 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3703 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3704 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3705 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3706 | EXPECT_EQ(407, response->headers->response_code()); |
| 3707 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3708 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3709 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3710 | // TODO(crbug.com/986744): Fix handling of OnConnected() when proxy |
| 3711 | // authentication is required. We should notify the callback that a connection |
| 3712 | // was established, even though the stream might not be ready for us to send |
| 3713 | // data through it. |
| 3714 | EXPECT_THAT(connected_handler.transports(), IsEmpty()); |
| 3715 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3716 | LoadTimingInfo load_timing_info; |
| 3717 | // CONNECT requests and responses are handled at the connect job level, so |
| 3718 | // the transaction does not yet have a connection. |
| 3719 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3721 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3723 | rv = trans->RestartWithAuth( |
| 3724 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3726 | |
| 3727 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3728 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3729 | |
| 3730 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3731 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3732 | |
| 3733 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3734 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3735 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3736 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3737 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 3738 | TransportInfo expected_transport; |
| 3739 | expected_transport.type = TransportType::kProxied; |
| 3740 | expected_transport.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 70); |
| 3741 | EXPECT_THAT(connected_handler.transports(), ElementsAre(expected_transport)); |
| 3742 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3743 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3744 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3745 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3746 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3747 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3748 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3749 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3750 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3751 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3752 | } |
| 3753 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3754 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3755 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3756 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3757 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3758 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3759 | // reused. See http://crbug.com/544255. |
| 3760 | for (int i = 0; i < 2; ++i) { |
| 3761 | HttpRequestInfo request; |
| 3762 | request.method = "GET"; |
| 3763 | request.url = GURL("https://www.example.org/"); |
| 3764 | // Ensure that proxy authentication is attempted even |
| 3765 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 3766 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3767 | request.traffic_annotation = |
| 3768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3769 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3770 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3771 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3772 | ConfiguredProxyResolutionService::CreateFixed( |
| 3773 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3774 | RecordingBoundTestNetLog log; |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3775 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3778 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3779 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3780 | // Since we have proxy, should try to establish tunnel. |
| 3781 | MockWrite data_writes1[] = { |
| 3782 | MockWrite(ASYNC, 0, |
| 3783 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3784 | "Host: www.example.org:443\r\n" |
| 3785 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3787 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3788 | // be issuing -- the final header line contains the credentials. |
| 3789 | MockWrite(ASYNC, 3, |
| 3790 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3791 | "Host: www.example.org:443\r\n" |
| 3792 | "Proxy-Connection: keep-alive\r\n" |
| 3793 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3794 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3795 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3796 | // The proxy responds to the connect with a 407, using a persistent |
| 3797 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3798 | MockRead data_reads1[] = { |
| 3799 | // No credentials. |
| 3800 | MockRead(ASYNC, 1, |
| 3801 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3802 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3803 | "Proxy-Connection: keep-alive\r\n" |
| 3804 | "Content-Length: 10\r\n\r\n"), |
| 3805 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3806 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3807 | // Wrong credentials (wrong password). |
| 3808 | MockRead(ASYNC, 4, |
| 3809 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3810 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3811 | "Proxy-Connection: keep-alive\r\n" |
| 3812 | "Content-Length: 10\r\n\r\n"), |
| 3813 | // No response body because the test stops reading here. |
| 3814 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3815 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3816 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3817 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3818 | data1.set_busy_before_sync_reads(true); |
| 3819 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3820 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3821 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3823 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3824 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3825 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3826 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3827 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3828 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3829 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3830 | ExpectLogContainsSomewhere( |
| 3831 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3832 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3833 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3835 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3836 | ASSERT_TRUE(response); |
| 3837 | ASSERT_TRUE(response->headers); |
| 3838 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3839 | EXPECT_EQ(407, response->headers->response_code()); |
| 3840 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3841 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3842 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3843 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3844 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3845 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3846 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3847 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3848 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3849 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3851 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3852 | ASSERT_TRUE(response); |
| 3853 | ASSERT_TRUE(response->headers); |
| 3854 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3855 | EXPECT_EQ(407, response->headers->response_code()); |
| 3856 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3857 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3858 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3859 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3860 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3861 | // out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3862 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3863 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3867 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3868 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3869 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3870 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3871 | // reused. See http://crbug.com/544255. |
| 3872 | for (int i = 0; i < 2; ++i) { |
| 3873 | HttpRequestInfo request; |
| 3874 | request.method = "GET"; |
| 3875 | request.url = GURL("https://www.example.org/"); |
| 3876 | // Ensure that proxy authentication is attempted even |
| 3877 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 3878 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3879 | request.traffic_annotation = |
| 3880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3881 | |
| 3882 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3883 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3884 | ConfiguredProxyResolutionService::CreateFixed( |
| 3885 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3886 | RecordingBoundTestNetLog log; |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3887 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3891 | |
| 3892 | // Since we have proxy, should try to establish tunnel. |
| 3893 | MockWrite data_writes1[] = { |
| 3894 | MockWrite(ASYNC, 0, |
| 3895 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3896 | "Host: www.example.org:443\r\n" |
| 3897 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3899 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3900 | // be issuing -- the final header line contains the credentials. |
| 3901 | MockWrite(ASYNC, 3, |
| 3902 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3903 | "Host: www.example.org:443\r\n" |
| 3904 | "Proxy-Connection: keep-alive\r\n" |
| 3905 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3906 | }; |
| 3907 | |
| 3908 | // The proxy responds to the connect with a 407, using a persistent |
| 3909 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3910 | MockRead data_reads1[] = { |
| 3911 | // No credentials. |
| 3912 | MockRead(ASYNC, 1, |
| 3913 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3914 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3915 | "Content-Length: 10\r\n\r\n"), |
| 3916 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3917 | |
| 3918 | // Wrong credentials (wrong password). |
| 3919 | MockRead(ASYNC, 4, |
| 3920 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3921 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3922 | "Content-Length: 10\r\n\r\n"), |
| 3923 | // No response body because the test stops reading here. |
| 3924 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3925 | }; |
| 3926 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3927 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3928 | data1.set_busy_before_sync_reads(true); |
| 3929 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3930 | |
| 3931 | TestCompletionCallback callback1; |
| 3932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3933 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3934 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3935 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3936 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3937 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3938 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3939 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3940 | ExpectLogContainsSomewhere( |
| 3941 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3942 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3943 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [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()); |
| 3950 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3951 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3952 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3953 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3954 | |
| 3955 | TestCompletionCallback callback2; |
| 3956 | |
| 3957 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3958 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3959 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3960 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3962 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3963 | ASSERT_TRUE(response); |
| 3964 | ASSERT_TRUE(response->headers); |
| 3965 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3966 | EXPECT_EQ(407, response->headers->response_code()); |
| 3967 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3968 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3969 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3970 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3971 | |
| 3972 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3973 | // out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 3974 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3979 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3980 | // the case the server sends extra data on the original socket, so it can't be |
| 3981 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3982 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3983 | HttpRequestInfo request; |
| 3984 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3985 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3986 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 3987 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3988 | request.traffic_annotation = |
| 3989 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3990 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3991 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3992 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 3993 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3994 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 3995 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3996 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3997 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3998 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3999 | // Since we have proxy, should try to establish tunnel. |
| 4000 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4001 | MockWrite(ASYNC, 0, |
| 4002 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4003 | "Host: www.example.org:443\r\n" |
| 4004 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4005 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4006 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4007 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 4008 | // extra data, so the socket cannot be reused. |
| 4009 | MockRead data_reads1[] = { |
| 4010 | // No credentials. |
| 4011 | MockRead(ASYNC, 1, |
| 4012 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 4013 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4014 | "Content-Length: 10\r\n\r\n"), |
| 4015 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 4016 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 4017 | }; |
| 4018 | |
| 4019 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4020 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4021 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4022 | MockWrite(ASYNC, 0, |
| 4023 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4024 | "Host: www.example.org:443\r\n" |
| 4025 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4026 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4027 | |
| 4028 | MockWrite(ASYNC, 2, |
| 4029 | "GET / HTTP/1.1\r\n" |
| 4030 | "Host: www.example.org\r\n" |
| 4031 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4032 | }; |
| 4033 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4034 | MockRead data_reads2[] = { |
| 4035 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4036 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4037 | MockRead(ASYNC, 3, |
| 4038 | "HTTP/1.1 200 OK\r\n" |
| 4039 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 4040 | "Content-Length: 5\r\n\r\n"), |
| 4041 | // No response body because the test stops reading here. |
| 4042 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4043 | }; |
| 4044 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4045 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4046 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4047 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4048 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4049 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4050 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4053 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4054 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4055 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4056 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4057 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4058 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4059 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4060 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 4061 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 4062 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4063 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4064 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 4065 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4066 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4067 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4068 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4069 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4070 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4071 | ASSERT_TRUE(response); |
| 4072 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4073 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4074 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4075 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4076 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4077 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4078 | LoadTimingInfo load_timing_info; |
| 4079 | // CONNECT requests and responses are handled at the connect job level, so |
| 4080 | // the transaction does not yet have a connection. |
| 4081 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4083 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4084 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4085 | rv = |
| 4086 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4087 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4088 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4089 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4090 | EXPECT_EQ(200, response->headers->response_code()); |
| 4091 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4092 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 4093 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4094 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4095 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4096 | |
| 4097 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4098 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4099 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4100 | |
| 4101 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4102 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 4103 | } |
| 4104 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4105 | // Test the case a proxy closes a socket while the challenge body is being |
| 4106 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4107 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4108 | HttpRequestInfo request; |
| 4109 | request.method = "GET"; |
| 4110 | request.url = GURL("https://www.example.org/"); |
| 4111 | // Ensure that proxy authentication is attempted even |
| 4112 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 4113 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4114 | request.traffic_annotation = |
| 4115 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4116 | |
| 4117 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4118 | session_deps_.proxy_resolution_service = |
| 4119 | ConfiguredProxyResolutionService::CreateFixed( |
| 4120 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4121 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4123 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4124 | |
| 4125 | // Since we have proxy, should try to establish tunnel. |
| 4126 | MockWrite data_writes1[] = { |
| 4127 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4128 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4129 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4130 | }; |
| 4131 | |
| 4132 | // The proxy responds to the connect with a 407, using a persistent |
| 4133 | // connection. |
| 4134 | MockRead data_reads1[] = { |
| 4135 | // No credentials. |
| 4136 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4137 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4138 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 4139 | // Server hands up in the middle of the body. |
| 4140 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 4141 | }; |
| 4142 | |
| 4143 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4144 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4145 | // be issuing -- the final header line contains the credentials. |
| 4146 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4147 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4148 | "Proxy-Connection: keep-alive\r\n" |
| 4149 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4150 | |
| 4151 | MockWrite("GET / HTTP/1.1\r\n" |
| 4152 | "Host: www.example.org\r\n" |
| 4153 | "Connection: keep-alive\r\n\r\n"), |
| 4154 | }; |
| 4155 | |
| 4156 | MockRead data_reads2[] = { |
| 4157 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4158 | |
| 4159 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4160 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4161 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4162 | MockRead(SYNCHRONOUS, "hello"), |
| 4163 | }; |
| 4164 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4165 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4166 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4167 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4168 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4169 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4171 | |
| 4172 | TestCompletionCallback callback; |
| 4173 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4174 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4175 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4177 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4178 | ASSERT_TRUE(response); |
| 4179 | ASSERT_TRUE(response->headers); |
| 4180 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4181 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4182 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4184 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4185 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4187 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4188 | ASSERT_TRUE(response); |
| 4189 | ASSERT_TRUE(response->headers); |
| 4190 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4191 | EXPECT_EQ(200, response->headers->response_code()); |
| 4192 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4193 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 4194 | EXPECT_EQ("hello", body); |
| 4195 | } |
| 4196 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4197 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 4198 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4199 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4200 | HttpRequestInfo request; |
| 4201 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4202 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4203 | request.traffic_annotation = |
| 4204 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4205 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4206 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4207 | session_deps_.proxy_resolution_service = |
| 4208 | ConfiguredProxyResolutionService::CreateFixed( |
| 4209 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4213 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4214 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4215 | // Since we have proxy, should try to establish tunnel. |
| 4216 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4217 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4218 | "Host: www.example.org:443\r\n" |
| 4219 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4220 | }; |
| 4221 | |
| 4222 | // The proxy responds to the connect with a 407. |
| 4223 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4224 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4225 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4226 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4227 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4228 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4229 | }; |
| 4230 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4231 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4232 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4234 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4235 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4236 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4237 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4238 | |
| 4239 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4242 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4243 | ASSERT_TRUE(response); |
| 4244 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4245 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4246 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4247 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4248 | |
| 4249 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4250 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4251 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4252 | |
| 4253 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4254 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4255 | } |
| 4256 | |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4257 | // Test the no-tunnel HTTP auth case where proxy and server origins and realms |
| 4258 | // are the same, but the user/passwords are different. Serves to verify |
| 4259 | // credentials are correctly separated based on HttpAuth::Target. |
| 4260 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyMatchesServerAuthNoTunnel) { |
| 4261 | HttpRequestInfo request; |
| 4262 | request.method = "GET"; |
| 4263 | request.url = GURL("http://myproxy:70/"); |
| 4264 | request.traffic_annotation = |
| 4265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4266 | |
| 4267 | // Proxy matches request URL. |
| 4268 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4269 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4270 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4271 | RecordingBoundTestNetLog log; |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4272 | session_deps_.net_log = log.bound().net_log(); |
| 4273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4274 | |
| 4275 | MockWrite data_writes[] = { |
| 4276 | // Initial request gets a proxy auth challenge. |
| 4277 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4278 | "Host: myproxy:70\r\n" |
| 4279 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4280 | // Retry with proxy auth credentials, which will result in a server auth |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4281 | // challenge. |
| 4282 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4283 | "Host: myproxy:70\r\n" |
| 4284 | "Proxy-Connection: keep-alive\r\n" |
| 4285 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4286 | // Retry with proxy and server auth credentials, which gets a response. |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4287 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4288 | "Host: myproxy:70\r\n" |
| 4289 | "Proxy-Connection: keep-alive\r\n" |
| 4290 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4291 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4292 | // A second request should preemptively send the correct proxy and server |
| 4293 | // auth headers. |
| 4294 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4295 | "Host: myproxy:70\r\n" |
| 4296 | "Proxy-Connection: keep-alive\r\n" |
| 4297 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4298 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4299 | }; |
| 4300 | |
| 4301 | MockRead data_reads[] = { |
| 4302 | // Proxy auth challenge. |
| 4303 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4304 | "Proxy-Connection: keep-alive\r\n" |
| 4305 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4306 | "Content-Length: 0\r\n\r\n"), |
| 4307 | // Server auth challenge. |
| 4308 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4309 | "Proxy-Connection: keep-alive\r\n" |
| 4310 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4311 | "Content-Length: 0\r\n\r\n"), |
| 4312 | // Response. |
| 4313 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4314 | "Proxy-Connection: keep-alive\r\n" |
| 4315 | "Content-Length: 5\r\n\r\n" |
| 4316 | "hello"), |
| 4317 | // Response to second request. |
| 4318 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4319 | "Proxy-Connection: keep-alive\r\n" |
| 4320 | "Content-Length: 2\r\n\r\n" |
| 4321 | "hi"), |
| 4322 | }; |
| 4323 | |
| 4324 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4325 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4326 | |
| 4327 | TestCompletionCallback callback; |
| 4328 | |
| 4329 | auto trans = |
| 4330 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4331 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4332 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4334 | ASSERT_TRUE(response); |
| 4335 | ASSERT_TRUE(response->headers); |
| 4336 | EXPECT_EQ(407, response->headers->response_code()); |
| 4337 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
| 4338 | |
| 4339 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4340 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4341 | response = trans->GetResponseInfo(); |
| 4342 | ASSERT_TRUE(response); |
| 4343 | EXPECT_EQ(401, response->headers->response_code()); |
| 4344 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4345 | EXPECT_EQ("http://myproxy:70", |
| 4346 | response->auth_challenge->challenger.Serialize()); |
| 4347 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4348 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4349 | |
| 4350 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4351 | callback.callback()); |
| 4352 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4353 | response = trans->GetResponseInfo(); |
| 4354 | ASSERT_TRUE(response); |
| 4355 | EXPECT_EQ(200, response->headers->response_code()); |
| 4356 | // The password prompt info should not be set. |
| 4357 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4358 | |
| 4359 | std::string response_data; |
| 4360 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4361 | EXPECT_EQ("hello", response_data); |
| 4362 | |
| 4363 | // Check that the credentials were cached correctly. |
| 4364 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4365 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4366 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey()); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4367 | ASSERT_TRUE(entry); |
| 4368 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4369 | ASSERT_EQ(kBar, entry->credentials().password()); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4370 | entry = session->http_auth_cache()->Lookup( |
| 4371 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4372 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey()); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4373 | ASSERT_TRUE(entry); |
| 4374 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4375 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4376 | |
| 4377 | // Make another request, which should automatically send the correct proxy and |
| 4378 | // server auth credentials and get another response. |
| 4379 | trans = |
| 4380 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4381 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4382 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4383 | response = trans->GetResponseInfo(); |
| 4384 | ASSERT_TRUE(response); |
| 4385 | EXPECT_EQ(200, response->headers->response_code()); |
| 4386 | // The password prompt info should not be set. |
| 4387 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4388 | |
| 4389 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4390 | EXPECT_EQ("hi", response_data); |
| 4391 | |
| 4392 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4393 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 4394 | } |
| 4395 | |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4396 | // Test the no-tunnel HTTP auth case where proxy and server origins and realms |
| 4397 | // are the same, but the user/passwords are different, and with different |
| 4398 | // NetworkIsolationKeys. Sends one request with a NIK, response to both proxy |
| 4399 | // and auth challenges, sends another request with another NIK, expecting only |
| 4400 | // the proxy credentials to be cached, and thus sees only a server auth |
| 4401 | // challenge. Then sends a request with the original NIK, expecting cached proxy |
| 4402 | // and auth credentials that match the ones used in the first request. |
| 4403 | // |
| 4404 | // Serves to verify credentials are correctly separated based on |
| 4405 | // HttpAuth::Target and NetworkIsolationKeys, but NetworkIsolationKey only |
| 4406 | // affects server credentials, not proxy credentials. |
| 4407 | TEST_F(HttpNetworkTransactionTest, |
| 4408 | BasicAuthProxyMatchesServerAuthWithNetworkIsolationKeyNoTunnel) { |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 4409 | const SchemefulSite kSite1(GURL("https://foo.test/")); |
| 4410 | const net::NetworkIsolationKey kNetworkIsolationKey1(kSite1, kSite1); |
| 4411 | const SchemefulSite kSite2(GURL("https://bar.test/")); |
| 4412 | const net::NetworkIsolationKey kNetworkIsolationKey2(kSite2, kSite2); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4413 | |
| 4414 | // This test would need to use a single socket without this option enabled. |
| 4415 | // Best to use this option when it would affect a test, as it will eventually |
| 4416 | // become the default behavior. |
| 4417 | base::test::ScopedFeatureList feature_list; |
| 4418 | feature_list.InitAndEnableFeature( |
| 4419 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 4420 | |
| 4421 | // Proxy matches request URL. |
| 4422 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4423 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4424 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4425 | RecordingBoundTestNetLog log; |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4426 | session_deps_.net_log = log.bound().net_log(); |
| 4427 | session_deps_.key_auth_cache_server_entries_by_network_isolation_key = true; |
| 4428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4429 | |
| 4430 | MockWrite data_writes[] = { |
| 4431 | // Initial request gets a proxy auth challenge. |
| 4432 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4433 | "Host: myproxy:70\r\n" |
| 4434 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4435 | // Retry with proxy auth credentials, which will result in a server auth |
| 4436 | // challenge. |
| 4437 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4438 | "Host: myproxy:70\r\n" |
| 4439 | "Proxy-Connection: keep-alive\r\n" |
| 4440 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4441 | // Retry with proxy and server auth credentials, which gets a response. |
| 4442 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4443 | "Host: myproxy:70\r\n" |
| 4444 | "Proxy-Connection: keep-alive\r\n" |
| 4445 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4446 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4447 | // Another request to the same server and using the same NIK should |
| 4448 | // preemptively send the correct cached proxy and server |
| 4449 | // auth headers. |
| 4450 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4451 | "Host: myproxy:70\r\n" |
| 4452 | "Proxy-Connection: keep-alive\r\n" |
| 4453 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4454 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4455 | }; |
| 4456 | |
| 4457 | MockRead data_reads[] = { |
| 4458 | // Proxy auth challenge. |
| 4459 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4460 | "Proxy-Connection: keep-alive\r\n" |
| 4461 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4462 | "Content-Length: 0\r\n\r\n"), |
| 4463 | // Server auth challenge. |
| 4464 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4465 | "Proxy-Connection: keep-alive\r\n" |
| 4466 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4467 | "Content-Length: 0\r\n\r\n"), |
| 4468 | // Response. |
| 4469 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4470 | "Proxy-Connection: keep-alive\r\n" |
| 4471 | "Content-Length: 5\r\n\r\n" |
| 4472 | "hello"), |
| 4473 | // Response to second request. |
| 4474 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4475 | "Proxy-Connection: keep-alive\r\n" |
| 4476 | "Content-Length: 2\r\n\r\n" |
| 4477 | "hi"), |
| 4478 | }; |
| 4479 | |
| 4480 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4481 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4482 | |
| 4483 | MockWrite data_writes2[] = { |
| 4484 | // Initial request using a different NetworkIsolationKey includes the |
| 4485 | // cached proxy credentials, but not server credentials. |
| 4486 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4487 | "Host: myproxy:70\r\n" |
| 4488 | "Proxy-Connection: keep-alive\r\n" |
| 4489 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4490 | // Retry with proxy and new server auth credentials, which gets a |
| 4491 | // response. |
| 4492 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4493 | "Host: myproxy:70\r\n" |
| 4494 | "Proxy-Connection: keep-alive\r\n" |
| 4495 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4496 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 4497 | }; |
| 4498 | |
| 4499 | MockRead data_reads2[] = { |
| 4500 | // Server auth challenge. |
| 4501 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4502 | "Proxy-Connection: keep-alive\r\n" |
| 4503 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4504 | "Content-Length: 0\r\n\r\n"), |
| 4505 | // Response. |
| 4506 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4507 | "Proxy-Connection: keep-alive\r\n" |
| 4508 | "Content-Length: 9\r\n\r\n" |
| 4509 | "greetings"), |
| 4510 | }; |
| 4511 | |
| 4512 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 4513 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4514 | |
| 4515 | TestCompletionCallback callback; |
| 4516 | |
| 4517 | HttpRequestInfo request; |
| 4518 | request.method = "GET"; |
| 4519 | request.url = GURL("http://myproxy:70/"); |
| 4520 | request.traffic_annotation = |
| 4521 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4522 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4523 | |
| 4524 | auto trans = |
| 4525 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4526 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4527 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4528 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4529 | ASSERT_TRUE(response); |
| 4530 | ASSERT_TRUE(response->headers); |
| 4531 | EXPECT_EQ(407, response->headers->response_code()); |
| 4532 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
| 4533 | |
| 4534 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4535 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4536 | response = trans->GetResponseInfo(); |
| 4537 | ASSERT_TRUE(response); |
| 4538 | EXPECT_EQ(401, response->headers->response_code()); |
| 4539 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4540 | EXPECT_EQ("http://myproxy:70", |
| 4541 | response->auth_challenge->challenger.Serialize()); |
| 4542 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4543 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4544 | |
| 4545 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4546 | callback.callback()); |
| 4547 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4548 | response = trans->GetResponseInfo(); |
| 4549 | ASSERT_TRUE(response); |
| 4550 | EXPECT_EQ(200, response->headers->response_code()); |
| 4551 | // The password prompt info should not be set. |
| 4552 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4553 | std::string response_data; |
| 4554 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4555 | EXPECT_EQ("hello", response_data); |
| 4556 | |
| 4557 | // Check that the proxy credentials were cached correctly. The should be |
| 4558 | // accessible with any NetworkIsolationKey. |
| 4559 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4560 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4561 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4562 | ASSERT_TRUE(entry); |
| 4563 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4564 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4565 | EXPECT_EQ(entry, |
| 4566 | session->http_auth_cache()->Lookup( |
| 4567 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4568 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4569 | |
| 4570 | // Check that the server credentials were cached correctly. The should be |
| 4571 | // accessible with only kNetworkIsolationKey1. |
| 4572 | entry = session->http_auth_cache()->Lookup( |
| 4573 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4574 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4575 | ASSERT_TRUE(entry); |
| 4576 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4577 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4578 | // Looking up the server entry with another NetworkIsolationKey should fail. |
| 4579 | EXPECT_FALSE(session->http_auth_cache()->Lookup( |
| 4580 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4581 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4582 | |
| 4583 | // Make another request with a different NetworkIsolationKey. It should use |
| 4584 | // another socket, reuse the cached proxy credentials, but result in a server |
| 4585 | // auth challenge. |
| 4586 | request.network_isolation_key = kNetworkIsolationKey2; |
| 4587 | trans = |
| 4588 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4589 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4590 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4591 | response = trans->GetResponseInfo(); |
| 4592 | ASSERT_TRUE(response); |
| 4593 | EXPECT_EQ(401, response->headers->response_code()); |
| 4594 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4595 | EXPECT_EQ("http://myproxy:70", |
| 4596 | response->auth_challenge->challenger.Serialize()); |
| 4597 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4598 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4599 | |
| 4600 | rv = trans->RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 4601 | callback.callback()); |
| 4602 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4603 | response = trans->GetResponseInfo(); |
| 4604 | ASSERT_TRUE(response); |
| 4605 | EXPECT_EQ(200, response->headers->response_code()); |
| 4606 | // The password prompt info should not be set. |
| 4607 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4608 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4609 | EXPECT_EQ("greetings", response_data); |
| 4610 | |
| 4611 | // Check that the proxy credentials are still cached. |
| 4612 | entry = session->http_auth_cache()->Lookup( |
| 4613 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4614 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4615 | ASSERT_TRUE(entry); |
| 4616 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4617 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4618 | EXPECT_EQ(entry, |
| 4619 | session->http_auth_cache()->Lookup( |
| 4620 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4621 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4622 | |
| 4623 | // Check that the correct server credentials are cached for each |
| 4624 | // NetworkIsolationKey. |
| 4625 | entry = session->http_auth_cache()->Lookup( |
| 4626 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4627 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4628 | ASSERT_TRUE(entry); |
| 4629 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4630 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4631 | entry = session->http_auth_cache()->Lookup( |
| 4632 | GURL("http://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4633 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2); |
| 4634 | ASSERT_TRUE(entry); |
| 4635 | ASSERT_EQ(kFoo3, entry->credentials().username()); |
| 4636 | ASSERT_EQ(kBar3, entry->credentials().password()); |
| 4637 | |
| 4638 | // Make a request with the original NetworkIsolationKey. It should reuse the |
| 4639 | // first socket, and the proxy credentials sent on the first socket. |
| 4640 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4641 | trans = |
| 4642 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4643 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4644 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4645 | response = trans->GetResponseInfo(); |
| 4646 | ASSERT_TRUE(response); |
| 4647 | EXPECT_EQ(200, response->headers->response_code()); |
| 4648 | // The password prompt info should not be set. |
| 4649 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4650 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4651 | EXPECT_EQ("hi", response_data); |
| 4652 | |
| 4653 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4654 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | // Much like the test above, but uses tunnelled connections. |
| 4658 | TEST_F(HttpNetworkTransactionTest, |
| 4659 | BasicAuthProxyMatchesServerAuthWithNetworkIsolationKeyWithTunnel) { |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 4660 | const SchemefulSite kSite1(GURL("https://foo.test/")); |
| 4661 | const net::NetworkIsolationKey kNetworkIsolationKey1(kSite1, kSite1); |
| 4662 | const SchemefulSite kSite2(GURL("https://bar.test/")); |
| 4663 | const net::NetworkIsolationKey kNetworkIsolationKey2(kSite2, kSite2); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4664 | |
| 4665 | // This test would need to use a single socket without this option enabled. |
| 4666 | // Best to use this option when it would affect a test, as it will eventually |
| 4667 | // become the default behavior. |
| 4668 | base::test::ScopedFeatureList feature_list; |
| 4669 | feature_list.InitAndEnableFeature( |
| 4670 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 4671 | |
| 4672 | // Proxy matches request URL. |
| 4673 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4674 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4675 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 4676 | RecordingBoundTestNetLog log; |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4677 | session_deps_.net_log = log.bound().net_log(); |
| 4678 | session_deps_.key_auth_cache_server_entries_by_network_isolation_key = true; |
| 4679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4680 | |
| 4681 | MockWrite data_writes[] = { |
| 4682 | // Initial tunnel request gets a proxy auth challenge. |
| 4683 | MockWrite("CONNECT myproxy:70 HTTP/1.1\r\n" |
| 4684 | "Host: myproxy:70\r\n" |
| 4685 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4686 | // Retry with proxy auth credentials, which will result in establishing a |
| 4687 | // tunnel. |
| 4688 | MockWrite("CONNECT myproxy:70 HTTP/1.1\r\n" |
| 4689 | "Host: myproxy:70\r\n" |
| 4690 | "Proxy-Connection: keep-alive\r\n" |
| 4691 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4692 | // Request over the tunnel, which gets a server auth challenge. |
| 4693 | MockWrite("GET / HTTP/1.1\r\n" |
| 4694 | "Host: myproxy:70\r\n" |
| 4695 | "Connection: keep-alive\r\n\r\n"), |
| 4696 | // Retry with server auth credentials, which gets a response. |
| 4697 | MockWrite("GET / HTTP/1.1\r\n" |
| 4698 | "Host: myproxy:70\r\n" |
| 4699 | "Connection: keep-alive\r\n" |
| 4700 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4701 | // Another request to the same server and using the same NIK should |
| 4702 | // preemptively send the correct cached server |
| 4703 | // auth header. Since a tunnel was already established, the proxy headers |
| 4704 | // won't be sent again except when establishing another tunnel. |
| 4705 | MockWrite("GET / HTTP/1.1\r\n" |
| 4706 | "Host: myproxy:70\r\n" |
| 4707 | "Connection: keep-alive\r\n" |
| 4708 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4709 | }; |
| 4710 | |
| 4711 | MockRead data_reads[] = { |
| 4712 | // Proxy auth challenge. |
| 4713 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4714 | "Proxy-Connection: keep-alive\r\n" |
| 4715 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4716 | "Content-Length: 0\r\n\r\n"), |
| 4717 | // Tunnel success |
| 4718 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4719 | // Server auth challenge. |
| 4720 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4721 | "Connection: keep-alive\r\n" |
| 4722 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4723 | "Content-Length: 0\r\n\r\n"), |
| 4724 | // Response. |
| 4725 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4726 | "Connection: keep-alive\r\n" |
| 4727 | "Content-Length: 5\r\n\r\n" |
| 4728 | "hello"), |
| 4729 | // Response to second request. |
| 4730 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4731 | "Connection: keep-alive\r\n" |
| 4732 | "Content-Length: 2\r\n\r\n" |
| 4733 | "hi"), |
| 4734 | }; |
| 4735 | |
| 4736 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4738 | // One for the proxy connection, one of the server connection. |
| 4739 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4741 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 4742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 4743 | |
| 4744 | MockWrite data_writes2[] = { |
| 4745 | // Initial request using a different NetworkIsolationKey includes the |
| 4746 | // cached proxy credentials when establishing a tunnel. |
| 4747 | MockWrite("CONNECT myproxy:70 HTTP/1.1\r\n" |
| 4748 | "Host: myproxy:70\r\n" |
| 4749 | "Proxy-Connection: keep-alive\r\n" |
| 4750 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4751 | // Request over the tunnel, which gets a server auth challenge. Cached |
| 4752 | // credentials cannot be used, since the NIK is different. |
| 4753 | MockWrite("GET / HTTP/1.1\r\n" |
| 4754 | "Host: myproxy:70\r\n" |
| 4755 | "Connection: keep-alive\r\n\r\n"), |
| 4756 | // Retry with server auth credentials, which gets a response. |
| 4757 | MockWrite("GET / HTTP/1.1\r\n" |
| 4758 | "Host: myproxy:70\r\n" |
| 4759 | "Connection: keep-alive\r\n" |
| 4760 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
| 4761 | }; |
| 4762 | |
| 4763 | MockRead data_reads2[] = { |
| 4764 | // Tunnel success |
| 4765 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4766 | // Server auth challenge. |
| 4767 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4768 | "Connection: keep-alive\r\n" |
| 4769 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4770 | "Content-Length: 0\r\n\r\n"), |
| 4771 | // Response. |
| 4772 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4773 | "Connection: keep-alive\r\n" |
| 4774 | "Content-Length: 9\r\n\r\n" |
| 4775 | "greetings"), |
| 4776 | }; |
| 4777 | |
| 4778 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 4779 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4780 | // One for the proxy connection, one of the server connection. |
| 4781 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 4782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 4783 | SSLSocketDataProvider ssl4(ASYNC, OK); |
| 4784 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl4); |
| 4785 | |
| 4786 | TestCompletionCallback callback; |
| 4787 | |
| 4788 | HttpRequestInfo request; |
| 4789 | request.method = "GET"; |
| 4790 | request.url = GURL("https://myproxy:70/"); |
| 4791 | request.traffic_annotation = |
| 4792 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4793 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4794 | |
| 4795 | auto trans = |
| 4796 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4797 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4798 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4799 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4800 | ASSERT_TRUE(response); |
| 4801 | ASSERT_TRUE(response->headers); |
| 4802 | EXPECT_EQ(407, response->headers->response_code()); |
| 4803 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
| 4804 | |
| 4805 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4806 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4807 | response = trans->GetResponseInfo(); |
| 4808 | ASSERT_TRUE(response); |
| 4809 | EXPECT_EQ(401, response->headers->response_code()); |
| 4810 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4811 | EXPECT_EQ("https://myproxy:70", |
| 4812 | response->auth_challenge->challenger.Serialize()); |
| 4813 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4814 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4815 | |
| 4816 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4817 | callback.callback()); |
| 4818 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4819 | response = trans->GetResponseInfo(); |
| 4820 | ASSERT_TRUE(response); |
| 4821 | EXPECT_EQ(200, response->headers->response_code()); |
| 4822 | // The password prompt info should not be set. |
| 4823 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4824 | std::string response_data; |
| 4825 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4826 | EXPECT_EQ("hello", response_data); |
| 4827 | |
| 4828 | // Check that the proxy credentials were cached correctly. The should be |
| 4829 | // accessible with any NetworkIsolationKey. |
| 4830 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4831 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4832 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4833 | ASSERT_TRUE(entry); |
| 4834 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4835 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4836 | EXPECT_EQ(entry, |
| 4837 | session->http_auth_cache()->Lookup( |
| 4838 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4839 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4840 | |
| 4841 | // Check that the server credentials were cached correctly. The should be |
| 4842 | // accessible with only kNetworkIsolationKey1. |
| 4843 | entry = session->http_auth_cache()->Lookup( |
| 4844 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4845 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4846 | ASSERT_TRUE(entry); |
| 4847 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4848 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4849 | // Looking up the server entry with another NetworkIsolationKey should fail. |
| 4850 | EXPECT_FALSE(session->http_auth_cache()->Lookup( |
| 4851 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4852 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4853 | |
| 4854 | // Make another request with a different NetworkIsolationKey. It should use |
| 4855 | // another socket, reuse the cached proxy credentials, but result in a server |
| 4856 | // auth challenge. |
| 4857 | request.network_isolation_key = kNetworkIsolationKey2; |
| 4858 | trans = |
| 4859 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4860 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4861 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4862 | response = trans->GetResponseInfo(); |
| 4863 | ASSERT_TRUE(response); |
| 4864 | EXPECT_EQ(401, response->headers->response_code()); |
| 4865 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4866 | EXPECT_EQ("https://myproxy:70", |
| 4867 | response->auth_challenge->challenger.Serialize()); |
| 4868 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4869 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4870 | |
| 4871 | rv = trans->RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 4872 | callback.callback()); |
| 4873 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4874 | response = trans->GetResponseInfo(); |
| 4875 | ASSERT_TRUE(response); |
| 4876 | EXPECT_EQ(200, response->headers->response_code()); |
| 4877 | // The password prompt info should not be set. |
| 4878 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4879 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4880 | EXPECT_EQ("greetings", response_data); |
| 4881 | |
| 4882 | // Check that the proxy credentials are still cached. |
| 4883 | entry = session->http_auth_cache()->Lookup( |
| 4884 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4885 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4886 | ASSERT_TRUE(entry); |
| 4887 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4888 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4889 | EXPECT_EQ(entry, |
| 4890 | session->http_auth_cache()->Lookup( |
| 4891 | GURL("https://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4892 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2)); |
| 4893 | |
| 4894 | // Check that the correct server credentials are cached for each |
| 4895 | // NetworkIsolationKey. |
| 4896 | entry = session->http_auth_cache()->Lookup( |
| 4897 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4898 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey1); |
| 4899 | ASSERT_TRUE(entry); |
| 4900 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4901 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4902 | entry = session->http_auth_cache()->Lookup( |
| 4903 | GURL("https://myproxy:70"), HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4904 | HttpAuth::AUTH_SCHEME_BASIC, kNetworkIsolationKey2); |
| 4905 | ASSERT_TRUE(entry); |
| 4906 | ASSERT_EQ(kFoo3, entry->credentials().username()); |
| 4907 | ASSERT_EQ(kBar3, entry->credentials().password()); |
| 4908 | |
| 4909 | // Make a request with the original NetworkIsolationKey. It should reuse the |
| 4910 | // first socket, and the proxy credentials sent on the first socket. |
| 4911 | request.network_isolation_key = kNetworkIsolationKey1; |
| 4912 | trans = |
| 4913 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4914 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4915 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4916 | response = trans->GetResponseInfo(); |
| 4917 | ASSERT_TRUE(response); |
| 4918 | EXPECT_EQ(200, response->headers->response_code()); |
| 4919 | // The password prompt info should not be set. |
| 4920 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4921 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4922 | EXPECT_EQ("hi", response_data); |
| 4923 | |
| 4924 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4925 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 4926 | } |
| 4927 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4928 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4929 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4930 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4931 | HttpRequestInfo request; |
| 4932 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4933 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4934 | request.traffic_annotation = |
| 4935 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4936 | |
| 4937 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 4938 | session_deps_.proxy_resolution_service = |
| 4939 | ConfiguredProxyResolutionService::CreateFixed( |
| 4940 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4944 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4945 | |
| 4946 | // Since we have proxy, should try to establish tunnel. |
| 4947 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4948 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4949 | "Host: www.example.org:443\r\n" |
| 4950 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4951 | }; |
| 4952 | |
| 4953 | // The proxy responds to the connect with a 407. |
| 4954 | MockRead data_reads[] = { |
| 4955 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4956 | MockRead("X-Foo: bar\r\n"), |
| 4957 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4958 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4959 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4960 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4961 | }; |
| 4962 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4963 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4964 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4965 | |
| 4966 | TestCompletionCallback callback; |
| 4967 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4968 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4970 | |
| 4971 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4972 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4974 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4975 | ASSERT_TRUE(response); |
| 4976 | ASSERT_TRUE(response->headers); |
| 4977 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4978 | EXPECT_EQ(407, response->headers->response_code()); |
| 4979 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4980 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4981 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4982 | |
| 4983 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4984 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4985 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4986 | |
| 4987 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 4988 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4989 | } |
| 4990 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4991 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4992 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4993 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4994 | HttpRequestInfo request; |
| 4995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4996 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4997 | request.traffic_annotation = |
| 4998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4999 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5000 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5003 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5004 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5005 | MockWrite( |
| 5006 | "GET / HTTP/1.1\r\n" |
| 5007 | "Host: www.example.org\r\n" |
| 5008 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5009 | }; |
| 5010 | |
| 5011 | MockRead data_reads1[] = { |
| 5012 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 5013 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5014 | // Large content-length -- won't matter, as connection will be reset. |
| 5015 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5016 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5017 | }; |
| 5018 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5019 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5020 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5022 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5023 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5024 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5026 | |
| 5027 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5028 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 5029 | } |
| 5030 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5031 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 5032 | // through a non-authenticating proxy. The request should fail with |
| 5033 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 5034 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 5035 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 5036 | // response came from the proxy or the server, so it is treated as if the proxy |
| 5037 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5038 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5039 | HttpRequestInfo request; |
| 5040 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5041 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5042 | request.traffic_annotation = |
| 5043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5044 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5045 | session_deps_.proxy_resolution_service = |
| 5046 | ConfiguredProxyResolutionService::CreateFixed( |
| 5047 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 5048 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5049 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5051 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5052 | // Since we have proxy, should try to establish tunnel. |
| 5053 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5054 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5055 | "Host: www.example.org:443\r\n" |
| 5056 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5057 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5058 | MockWrite("GET / HTTP/1.1\r\n" |
| 5059 | "Host: www.example.org\r\n" |
| 5060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5061 | }; |
| 5062 | |
| 5063 | MockRead data_reads1[] = { |
| 5064 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5065 | |
| 5066 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 5067 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5068 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5069 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5070 | }; |
| 5071 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5072 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5074 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5075 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5077 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5080 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5081 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5083 | |
| 5084 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5085 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 5086 | auto entries = log.GetEntries(); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5087 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 5088 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 5089 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5090 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 5091 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 5092 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 5093 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 5094 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5095 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5096 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 5097 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5098 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5099 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 5100 | HttpRequestInfo request; |
| 5101 | request.method = "GET"; |
| 5102 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5103 | request.traffic_annotation = |
| 5104 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5105 | |
| 5106 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5107 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5108 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5109 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5110 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5111 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5112 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5113 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5114 | mock_handler->set_allows_default_credentials(true); |
| 5115 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5116 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5117 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5118 | |
| 5119 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5120 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5121 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5122 | |
| 5123 | // Since we have proxy, should try to establish tunnel. |
| 5124 | MockWrite data_writes1[] = { |
| 5125 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5126 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5127 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5128 | }; |
| 5129 | |
| 5130 | // The proxy responds to the connect with a 407, using a non-persistent |
| 5131 | // connection. |
| 5132 | MockRead data_reads1[] = { |
| 5133 | // No credentials. |
| 5134 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5135 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 5136 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 5137 | }; |
| 5138 | |
| 5139 | // Since the first connection couldn't be reused, need to establish another |
| 5140 | // once given credentials. |
| 5141 | MockWrite data_writes2[] = { |
| 5142 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5143 | // be issuing -- the final header line contains the credentials. |
| 5144 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5145 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5146 | "Proxy-Connection: keep-alive\r\n" |
| 5147 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5148 | |
| 5149 | MockWrite("GET / HTTP/1.1\r\n" |
| 5150 | "Host: www.example.org\r\n" |
| 5151 | "Connection: keep-alive\r\n\r\n"), |
| 5152 | }; |
| 5153 | |
| 5154 | MockRead data_reads2[] = { |
| 5155 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 5156 | |
| 5157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5158 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5159 | MockRead("Content-Length: 5\r\n\r\n"), |
| 5160 | MockRead(SYNCHRONOUS, "hello"), |
| 5161 | }; |
| 5162 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5163 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5164 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5165 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5166 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5167 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5169 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5170 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5171 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5172 | |
| 5173 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5174 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5175 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5176 | |
| 5177 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5178 | ASSERT_TRUE(response); |
| 5179 | ASSERT_TRUE(response->headers); |
| 5180 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 5181 | EXPECT_EQ(407, response->headers->response_code()); |
| 5182 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5183 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5184 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5185 | |
| 5186 | LoadTimingInfo load_timing_info; |
| 5187 | // CONNECT requests and responses are handled at the connect job level, so |
| 5188 | // the transaction does not yet have a connection. |
| 5189 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5190 | |
| 5191 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5192 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5193 | response = trans->GetResponseInfo(); |
| 5194 | ASSERT_TRUE(response); |
| 5195 | ASSERT_TRUE(response->headers); |
| 5196 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5197 | EXPECT_EQ(200, response->headers->response_code()); |
| 5198 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 5199 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5200 | |
| 5201 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5202 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5203 | |
| 5204 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5205 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5206 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5207 | |
| 5208 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5209 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 5213 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5214 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5215 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 5216 | HttpRequestInfo request; |
| 5217 | request.method = "GET"; |
| 5218 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5219 | request.traffic_annotation = |
| 5220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5221 | |
| 5222 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5223 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5224 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5225 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5226 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5227 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5228 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5229 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5230 | mock_handler->set_allows_default_credentials(true); |
| 5231 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5232 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5233 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5234 | |
| 5235 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5236 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5237 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5238 | |
| 5239 | // Should try to establish tunnel. |
| 5240 | MockWrite data_writes1[] = { |
| 5241 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5242 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5243 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5244 | |
| 5245 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5246 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5247 | "Proxy-Connection: keep-alive\r\n" |
| 5248 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5249 | }; |
| 5250 | |
| 5251 | // The proxy responds to the connect with a 407, using a non-persistent |
| 5252 | // connection. |
| 5253 | MockRead data_reads1[] = { |
| 5254 | // No credentials. |
| 5255 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5256 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 5257 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5258 | }; |
| 5259 | |
| 5260 | // Since the first connection was closed, need to establish another once given |
| 5261 | // credentials. |
| 5262 | MockWrite data_writes2[] = { |
| 5263 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5264 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5265 | "Proxy-Connection: keep-alive\r\n" |
| 5266 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5267 | |
| 5268 | MockWrite("GET / HTTP/1.1\r\n" |
| 5269 | "Host: www.example.org\r\n" |
| 5270 | "Connection: keep-alive\r\n\r\n"), |
| 5271 | }; |
| 5272 | |
| 5273 | MockRead data_reads2[] = { |
| 5274 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 5275 | |
| 5276 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5277 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5278 | MockRead("Content-Length: 5\r\n\r\n"), |
| 5279 | MockRead(SYNCHRONOUS, "hello"), |
| 5280 | }; |
| 5281 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5282 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5283 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5284 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5285 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5286 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5287 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5288 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5289 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5290 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5291 | |
| 5292 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5293 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5294 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5295 | |
| 5296 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5297 | ASSERT_TRUE(response); |
| 5298 | ASSERT_TRUE(response->headers); |
| 5299 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5300 | EXPECT_EQ(407, response->headers->response_code()); |
| 5301 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5302 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5303 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5304 | |
| 5305 | LoadTimingInfo load_timing_info; |
| 5306 | // CONNECT requests and responses are handled at the connect job level, so |
| 5307 | // the transaction does not yet have a connection. |
| 5308 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5309 | |
| 5310 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5311 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5312 | |
| 5313 | response = trans->GetResponseInfo(); |
| 5314 | ASSERT_TRUE(response); |
| 5315 | ASSERT_TRUE(response->headers); |
| 5316 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5317 | EXPECT_EQ(200, response->headers->response_code()); |
| 5318 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 5319 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5320 | |
| 5321 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5322 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5323 | |
| 5324 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5325 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 5326 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5327 | |
| 5328 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5329 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 5333 | // that hangs up when credentials are initially sent, and hangs up again when |
| 5334 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5335 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5336 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 5337 | HttpRequestInfo request; |
| 5338 | request.method = "GET"; |
| 5339 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5340 | request.traffic_annotation = |
| 5341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5342 | |
| 5343 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5344 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5345 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5346 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5347 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5348 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5349 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5350 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5351 | mock_handler->set_allows_default_credentials(true); |
| 5352 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5353 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5354 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5355 | |
| 5356 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5357 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5358 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5359 | |
| 5360 | // Should try to establish tunnel. |
| 5361 | MockWrite data_writes1[] = { |
| 5362 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5363 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5364 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5365 | |
| 5366 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5367 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5368 | "Proxy-Connection: keep-alive\r\n" |
| 5369 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5370 | }; |
| 5371 | |
| 5372 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 5373 | // second request is sent. |
| 5374 | MockRead data_reads1[] = { |
| 5375 | // No credentials. |
| 5376 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5377 | MockRead("Content-Length: 0\r\n"), |
| 5378 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5379 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 5380 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5381 | }; |
| 5382 | |
| 5383 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 5384 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 5385 | // request. |
| 5386 | MockWrite data_writes2[] = { |
| 5387 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5388 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5389 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5390 | }; |
| 5391 | |
| 5392 | // The proxy, having had more than enough of us, just hangs up. |
| 5393 | MockRead data_reads2[] = { |
| 5394 | // No credentials. |
| 5395 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5396 | }; |
| 5397 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5398 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5399 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5400 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5401 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5402 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5403 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5404 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5405 | |
| 5406 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5407 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5408 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5409 | |
| 5410 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5411 | ASSERT_TRUE(response); |
| 5412 | ASSERT_TRUE(response->headers); |
| 5413 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5414 | EXPECT_EQ(407, response->headers->response_code()); |
| 5415 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5416 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5417 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5418 | |
| 5419 | LoadTimingInfo load_timing_info; |
| 5420 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5421 | |
| 5422 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5423 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5424 | |
| 5425 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5426 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5427 | } |
| 5428 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5429 | // This test exercises an odd edge case where the proxy closes the connection |
| 5430 | // after the authentication handshake is complete. Presumably this technique is |
| 5431 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 5432 | // succeeds, but the user is not authorized to connect to the destination |
| 5433 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 5434 | // site. |
| 5435 | TEST_F(HttpNetworkTransactionTest, |
| 5436 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 5437 | HttpRequestInfo request; |
| 5438 | request.method = "GET"; |
| 5439 | request.url = GURL("https://www.example.org/"); |
| 5440 | request.traffic_annotation = |
| 5441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5442 | |
| 5443 | // Configure against proxy server "myproxy:70". |
| 5444 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5445 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5446 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5447 | |
| 5448 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 5449 | auth_handler_factory->set_do_init_from_challenge(true); |
| 5450 | |
| 5451 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 5452 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 5453 | // was a real network error. |
| 5454 | // |
| 5455 | // The handlers support both default and explicit credentials. The retry |
| 5456 | // mentioned above should be able to reuse the default identity. Thus there |
| 5457 | // should never be a need to prompt for explicit credentials. |
| 5458 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 5459 | mock_handler->set_allows_default_credentials(true); |
| 5460 | mock_handler->set_allows_explicit_credentials(true); |
| 5461 | mock_handler->set_connection_based(true); |
| 5462 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5463 | HttpAuth::AUTH_PROXY); |
| 5464 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 5465 | mock_handler->set_allows_default_credentials(true); |
| 5466 | mock_handler->set_allows_explicit_credentials(true); |
| 5467 | mock_handler->set_connection_based(true); |
| 5468 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5469 | HttpAuth::AUTH_PROXY); |
| 5470 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 5471 | |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5472 | session_deps_.net_log = NetLog::Get(); |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5473 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5474 | |
| 5475 | // Data for both sockets. |
| 5476 | // |
| 5477 | // Writes are for the tunnel establishment attempts and the |
| 5478 | // authentication handshake. |
| 5479 | MockWrite data_writes1[] = { |
| 5480 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5481 | "Host: www.example.org:443\r\n" |
| 5482 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5483 | |
| 5484 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5485 | "Host: www.example.org:443\r\n" |
| 5486 | "Proxy-Connection: keep-alive\r\n" |
| 5487 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5488 | |
| 5489 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5490 | "Host: www.example.org:443\r\n" |
| 5491 | "Proxy-Connection: keep-alive\r\n" |
| 5492 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5493 | }; |
| 5494 | |
| 5495 | // The server side of the authentication handshake. Note that the response to |
| 5496 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 5497 | MockRead data_reads1[] = { |
| 5498 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5499 | MockRead("Content-Length: 0\r\n"), |
| 5500 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5501 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 5502 | |
| 5503 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5504 | MockRead("Content-Length: 0\r\n"), |
| 5505 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5506 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 5507 | |
| 5508 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 5509 | }; |
| 5510 | |
| 5511 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 5512 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5513 | |
| 5514 | // The second socket is for the reconnection attempt. Data is identical to the |
| 5515 | // first attempt. |
| 5516 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 5517 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5518 | |
| 5519 | auto trans = |
| 5520 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 5521 | |
| 5522 | TestCompletionCallback callback; |
| 5523 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5524 | |
| 5525 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 5526 | // stack. |
| 5527 | for (int i = 0; i < 4; ++i) { |
| 5528 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5529 | |
| 5530 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5531 | ASSERT_TRUE(response); |
| 5532 | ASSERT_TRUE(response->headers); |
| 5533 | EXPECT_EQ(407, response->headers->response_code()); |
| 5534 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5535 | |
| 5536 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 5537 | } |
| 5538 | |
| 5539 | // One shall be the number thou shalt retry, and the number of the retrying |
| 5540 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 5541 | // that thou then proceed to one. Three is right out. Once the number one, |
| 5542 | // being the first number, be reached, then lobbest thou thy |
| 5543 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 5544 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 5545 | |
| 5546 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5547 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 5548 | } |
| 5549 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5550 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 5551 | // that hangs up when credentials are initially sent, and sends a challenge |
| 5552 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5553 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5554 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 5555 | HttpRequestInfo request; |
| 5556 | request.method = "GET"; |
| 5557 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5558 | request.traffic_annotation = |
| 5559 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5560 | |
| 5561 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5562 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5563 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5564 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5565 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5566 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5567 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5568 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5569 | mock_handler->set_allows_default_credentials(true); |
| 5570 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5571 | HttpAuth::AUTH_PROXY); |
| 5572 | // Add another handler for the second challenge. It supports default |
| 5573 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5574 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5575 | mock_handler->set_allows_default_credentials(true); |
| 5576 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5577 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 5578 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5579 | |
| 5580 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
Matt Mueller | de5dadf | 2019-11-27 20:11:58 | [diff] [blame] | 5581 | session_deps_.net_log = NetLog::Get(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5582 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5583 | |
| 5584 | // Should try to establish tunnel. |
| 5585 | MockWrite data_writes1[] = { |
| 5586 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5587 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5588 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5589 | }; |
| 5590 | |
| 5591 | // The proxy responds to the connect with a 407, using a non-persistent |
| 5592 | // connection. |
| 5593 | MockRead data_reads1[] = { |
| 5594 | // No credentials. |
| 5595 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5596 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 5597 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 5598 | }; |
| 5599 | |
| 5600 | // Since the first connection was closed, need to establish another once given |
| 5601 | // credentials. |
| 5602 | MockWrite data_writes2[] = { |
| 5603 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5604 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5605 | "Proxy-Connection: keep-alive\r\n" |
| 5606 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 5607 | }; |
| 5608 | |
| 5609 | MockRead data_reads2[] = { |
| 5610 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5611 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 5612 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 5613 | }; |
| 5614 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5615 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5616 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5617 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5618 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5619 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5621 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5622 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5623 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5624 | |
| 5625 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5626 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5627 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5628 | |
| 5629 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5630 | ASSERT_TRUE(response); |
| 5631 | ASSERT_TRUE(response->headers); |
| 5632 | EXPECT_EQ(407, response->headers->response_code()); |
| 5633 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5634 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5635 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5636 | |
| 5637 | LoadTimingInfo load_timing_info; |
| 5638 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5639 | |
| 5640 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5641 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5642 | response = trans->GetResponseInfo(); |
| 5643 | ASSERT_TRUE(response); |
| 5644 | ASSERT_TRUE(response->headers); |
| 5645 | EXPECT_EQ(407, response->headers->response_code()); |
| 5646 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5647 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5648 | |
| 5649 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5650 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 5651 | } |
| 5652 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5653 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 5654 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 5655 | // unnecessarily invalidated, and that if the server co-operates, the |
| 5656 | // authentication handshake can continue with the same scheme but with a |
| 5657 | // different identity. |
| 5658 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 5659 | HttpRequestInfo request; |
| 5660 | request.method = "GET"; |
| 5661 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5662 | request.traffic_annotation = |
| 5663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5664 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5665 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5666 | auth_handler_factory->set_do_init_from_challenge(true); |
| 5667 | |
| 5668 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5669 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5670 | mock_handler->set_allows_default_credentials(true); |
| 5671 | mock_handler->set_allows_explicit_credentials(true); |
| 5672 | mock_handler->set_connection_based(true); |
| 5673 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 5674 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5675 | HttpAuth::AUTH_SERVER); |
| 5676 | |
| 5677 | // Add another handler for the second challenge. It supports default |
| 5678 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5679 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5680 | mock_handler->set_allows_default_credentials(true); |
| 5681 | mock_handler->set_allows_explicit_credentials(true); |
| 5682 | mock_handler->set_connection_based(true); |
| 5683 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 5684 | HttpAuth::AUTH_SERVER); |
| 5685 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 5686 | |
| 5687 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5688 | |
| 5689 | MockWrite data_writes1[] = { |
| 5690 | MockWrite("GET / HTTP/1.1\r\n" |
| 5691 | "Host: www.example.org\r\n" |
| 5692 | "Connection: keep-alive\r\n\r\n"), |
| 5693 | }; |
| 5694 | |
| 5695 | MockRead data_reads1[] = { |
| 5696 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 5697 | "WWW-Authenticate: Mock\r\n" |
| 5698 | "Connection: keep-alive\r\n\r\n"), |
| 5699 | }; |
| 5700 | |
| 5701 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 5702 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 5703 | // transaction procceds without an authorization header. |
| 5704 | MockWrite data_writes2[] = { |
| 5705 | MockWrite("GET / HTTP/1.1\r\n" |
| 5706 | "Host: www.example.org\r\n" |
| 5707 | "Connection: keep-alive\r\n\r\n"), |
| 5708 | }; |
| 5709 | |
| 5710 | MockRead data_reads2[] = { |
| 5711 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 5712 | "WWW-Authenticate: Mock\r\n" |
| 5713 | "Connection: keep-alive\r\n\r\n"), |
| 5714 | }; |
| 5715 | |
| 5716 | MockWrite data_writes3[] = { |
| 5717 | MockWrite("GET / HTTP/1.1\r\n" |
| 5718 | "Host: www.example.org\r\n" |
| 5719 | "Connection: keep-alive\r\n" |
| 5720 | "Authorization: auth_token\r\n\r\n"), |
| 5721 | }; |
| 5722 | |
| 5723 | MockRead data_reads3[] = { |
| 5724 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5725 | "Content-Length: 5\r\n" |
| 5726 | "Content-Type: text/plain\r\n" |
| 5727 | "Connection: keep-alive\r\n\r\n" |
| 5728 | "Hello"), |
| 5729 | }; |
| 5730 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5731 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5732 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5733 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5734 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5735 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5736 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5737 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5738 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 5739 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5740 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5741 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5742 | |
| 5743 | TestCompletionCallback callback; |
| 5744 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5745 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5746 | |
| 5747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5748 | ASSERT_TRUE(response); |
| 5749 | ASSERT_TRUE(response->headers); |
| 5750 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5751 | |
| 5752 | // The following three tests assert that an authentication challenge was |
| 5753 | // received and that the stack is ready to respond to the challenge using |
| 5754 | // ambient credentials. |
| 5755 | EXPECT_EQ(401, response->headers->response_code()); |
| 5756 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5757 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5758 | |
| 5759 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 5760 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5761 | response = trans->GetResponseInfo(); |
| 5762 | ASSERT_TRUE(response); |
| 5763 | ASSERT_TRUE(response->headers); |
| 5764 | |
| 5765 | // The following three tests assert that an authentication challenge was |
| 5766 | // received and that the stack needs explicit credentials before it is ready |
| 5767 | // to respond to the challenge. |
| 5768 | EXPECT_EQ(401, response->headers->response_code()); |
| 5769 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5770 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5771 | |
| 5772 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 5773 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5774 | response = trans->GetResponseInfo(); |
| 5775 | ASSERT_TRUE(response); |
| 5776 | ASSERT_TRUE(response->headers); |
| 5777 | EXPECT_EQ(200, response->headers->response_code()); |
| 5778 | |
| 5779 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 5780 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 5781 | } |
| 5782 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5783 | // Proxy resolver that returns a proxy with the same host and port for different |
| 5784 | // schemes, based on the path of the URL being requests. |
| 5785 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 5786 | public: |
| 5787 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 5788 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 5789 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 5790 | static constexpr uint16_t kProxyPort = 10000; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5791 | |
| 5792 | static HostPortPair ProxyHostPortPair() { |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 5793 | return HostPortPair("proxy.test", kProxyPort); |
| 5794 | } |
| 5795 | |
| 5796 | static std::string ProxyHostPortPairAsString() { |
| 5797 | return ProxyHostPortPair().ToString(); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | // ProxyResolver implementation. |
| 5801 | int GetProxyForURL(const GURL& url, |
Matt Menke | cd522ee0 | 2019-11-13 19:53:39 | [diff] [blame] | 5802 | const NetworkIsolationKey& network_isolation_key, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5803 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 5804 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5805 | std::unique_ptr<Request>* request, |
| 5806 | const NetLogWithSource& /*net_log*/) override { |
| 5807 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 5808 | results->set_traffic_annotation( |
| 5809 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5810 | if (url.path() == "/socks4") { |
| 5811 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 5812 | return OK; |
| 5813 | } |
| 5814 | if (url.path() == "/socks5") { |
| 5815 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 5816 | return OK; |
| 5817 | } |
| 5818 | if (url.path() == "/http") { |
| 5819 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 5820 | return OK; |
| 5821 | } |
| 5822 | if (url.path() == "/https") { |
| 5823 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 5824 | return OK; |
| 5825 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5826 | if (url.path() == "/https_trusted") { |
| 5827 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5828 | ProxyHostPortPair(), |
| 5829 | true /* is_trusted_proxy */)); |
| 5830 | return OK; |
| 5831 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5832 | NOTREACHED(); |
| 5833 | return ERR_NOT_IMPLEMENTED; |
| 5834 | } |
| 5835 | |
| 5836 | private: |
| 5837 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 5838 | }; |
| 5839 | |
| 5840 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 5841 | : public ProxyResolverFactory { |
| 5842 | public: |
| 5843 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 5844 | : ProxyResolverFactory(false) {} |
| 5845 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 5846 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 5847 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 5848 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 5849 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5850 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 5851 | return OK; |
| 5852 | } |
| 5853 | |
| 5854 | private: |
| 5855 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 5856 | }; |
| 5857 | |
| 5858 | // 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] | 5859 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5860 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 5861 | // request to foo.com using proxy.com as an HTTP proxy. |
| 5862 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5863 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 5864 | std::make_unique<ConfiguredProxyResolutionService>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5865 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5866 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5867 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 5868 | nullptr, /*quick_check_enabled=*/true); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5869 | |
| 5870 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5871 | |
| 5872 | MockWrite socks_writes[] = { |
| 5873 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 5874 | kSOCKS4OkRequestLocalHostPort80Length), |
| 5875 | MockWrite(SYNCHRONOUS, |
| 5876 | "GET /socks4 HTTP/1.1\r\n" |
| 5877 | "Host: test\r\n" |
| 5878 | "Connection: keep-alive\r\n\r\n"), |
| 5879 | }; |
| 5880 | MockRead socks_reads[] = { |
| 5881 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 5882 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5883 | "Connection: keep-alive\r\n" |
| 5884 | "Content-Length: 15\r\n\r\n" |
| 5885 | "SOCKS4 Response"), |
| 5886 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5887 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5888 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 5889 | |
| 5890 | const char kSOCKS5Request[] = { |
| 5891 | 0x05, // Version |
| 5892 | 0x01, // Command (CONNECT) |
| 5893 | 0x00, // Reserved |
| 5894 | 0x03, // Address type (DOMAINNAME) |
| 5895 | 0x04, // Length of domain (4) |
| 5896 | 't', 'e', 's', 't', // Domain string |
| 5897 | 0x00, 0x50, // 16-bit port (80) |
| 5898 | }; |
| 5899 | MockWrite socks5_writes[] = { |
| 5900 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5901 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5902 | MockWrite(SYNCHRONOUS, |
| 5903 | "GET /socks5 HTTP/1.1\r\n" |
| 5904 | "Host: test\r\n" |
| 5905 | "Connection: keep-alive\r\n\r\n"), |
| 5906 | }; |
| 5907 | MockRead socks5_reads[] = { |
| 5908 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5909 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5910 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5911 | "Connection: keep-alive\r\n" |
| 5912 | "Content-Length: 15\r\n\r\n" |
| 5913 | "SOCKS5 Response"), |
| 5914 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5915 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5916 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5917 | |
| 5918 | MockWrite http_writes[] = { |
| 5919 | MockWrite(SYNCHRONOUS, |
| 5920 | "GET http://test/http HTTP/1.1\r\n" |
| 5921 | "Host: test\r\n" |
| 5922 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5923 | }; |
| 5924 | MockRead http_reads[] = { |
| 5925 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5926 | "Proxy-Connection: keep-alive\r\n" |
| 5927 | "Content-Length: 13\r\n\r\n" |
| 5928 | "HTTP Response"), |
| 5929 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5930 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5931 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5932 | |
| 5933 | MockWrite https_writes[] = { |
| 5934 | MockWrite(SYNCHRONOUS, |
| 5935 | "GET http://test/https HTTP/1.1\r\n" |
| 5936 | "Host: test\r\n" |
| 5937 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5938 | }; |
| 5939 | MockRead https_reads[] = { |
| 5940 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5941 | "Proxy-Connection: keep-alive\r\n" |
| 5942 | "Content-Length: 14\r\n\r\n" |
| 5943 | "HTTPS Response"), |
| 5944 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5945 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5946 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5947 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5948 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5949 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5950 | MockWrite https_trusted_writes[] = { |
| 5951 | MockWrite(SYNCHRONOUS, |
| 5952 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5953 | "Host: test\r\n" |
| 5954 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5955 | }; |
| 5956 | MockRead https_trusted_reads[] = { |
| 5957 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5958 | "Proxy-Connection: keep-alive\r\n" |
| 5959 | "Content-Length: 22\r\n\r\n" |
| 5960 | "HTTPS Trusted Response"), |
| 5961 | }; |
| 5962 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5963 | https_trusted_writes); |
| 5964 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5965 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5966 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5967 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5968 | struct TestCase { |
| 5969 | GURL url; |
| 5970 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5971 | // 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] | 5972 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5973 | int expected_idle_socks4_sockets; |
| 5974 | int expected_idle_socks5_sockets; |
| 5975 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5976 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5977 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5978 | int expected_idle_https_sockets; |
| 5979 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5980 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5981 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5982 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5983 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5984 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5985 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5986 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5987 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5988 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5989 | }; |
| 5990 | |
| 5991 | for (const auto& test_case : kTestCases) { |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 5992 | SCOPED_TRACE(test_case.url); |
| 5993 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5994 | HttpRequestInfo request; |
| 5995 | request.method = "GET"; |
| 5996 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5997 | request.traffic_annotation = |
| 5998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 5999 | ConnectedHandler connected_handler; |
| 6000 | |
| 6001 | auto transaction = std::make_unique<HttpNetworkTransaction>( |
| 6002 | DEFAULT_PRIORITY, session.get()); |
| 6003 | |
| 6004 | transaction->SetConnectedCallback(connected_handler.Callback()); |
| 6005 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6006 | TestCompletionCallback callback; |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6007 | int rv = |
| 6008 | transaction->Start(&request, callback.callback(), NetLogWithSource()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6009 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6010 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6011 | const HttpResponseInfo* response = transaction->GetResponseInfo(); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6012 | ASSERT_TRUE(response); |
| 6013 | ASSERT_TRUE(response->headers); |
| 6014 | EXPECT_EQ(200, response->headers->response_code()); |
| 6015 | std::string response_data; |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6016 | EXPECT_THAT(ReadTransaction(transaction.get(), &response_data), IsOk()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6017 | EXPECT_EQ(test_case.expected_response, response_data); |
| 6018 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6019 | TransportInfo expected_transport; |
| 6020 | expected_transport.type = TransportType::kProxied; |
| 6021 | expected_transport.endpoint = |
| 6022 | IPEndPoint(IPAddress::IPv4Localhost(), |
| 6023 | SameProxyWithDifferentSchemesProxyResolver::kProxyPort); |
| 6024 | EXPECT_THAT(connected_handler.transports(), |
| 6025 | ElementsAre(expected_transport)); |
| 6026 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6027 | // Return the socket to the socket pool, so can make sure it's not used for |
| 6028 | // the next requests. |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6029 | transaction.reset(); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6030 | base::RunLoop().RunUntilIdle(); |
| 6031 | |
| 6032 | // Check the number of idle sockets in the pool, to make sure that used |
| 6033 | // sockets are indeed being returned to the socket pool. If each request |
| 6034 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 6035 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 6036 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 6037 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 6038 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 6039 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 6040 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 6041 | SameProxyWithDifferentSchemesProxyResolver:: |
| 6042 | ProxyHostPortPair())) |
| 6043 | ->IdleSocketCount()); |
| 6044 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 6045 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 6046 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 6047 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 6048 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 6049 | SameProxyWithDifferentSchemesProxyResolver:: |
| 6050 | ProxyHostPortPair())) |
| 6051 | ->IdleSocketCount()); |
| 6052 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 6053 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 6054 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 6055 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 6056 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 6057 | SameProxyWithDifferentSchemesProxyResolver:: |
| 6058 | ProxyHostPortPair())) |
| 6059 | ->IdleSocketCount()); |
| 6060 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 6061 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 6062 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 6063 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 6064 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 6065 | SameProxyWithDifferentSchemesProxyResolver:: |
| 6066 | ProxyHostPortPair())) |
| 6067 | ->IdleSocketCount()); |
| 6068 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 6069 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 6070 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 6071 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 6072 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 6073 | SameProxyWithDifferentSchemesProxyResolver:: |
| 6074 | ProxyHostPortPair(), |
| 6075 | true /* is_trusted_proxy */)) |
| 6076 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 6077 | } |
| 6078 | } |
| 6079 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6080 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6081 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6082 | HttpRequestInfo request1; |
| 6083 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6084 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6085 | request1.traffic_annotation = |
| 6086 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6087 | |
| 6088 | HttpRequestInfo request2; |
| 6089 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6090 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6091 | request2.traffic_annotation = |
| 6092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6093 | |
| 6094 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6095 | session_deps_.proxy_resolution_service = |
| 6096 | ConfiguredProxyResolutionService::CreateFixed( |
| 6097 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6098 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6099 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6101 | |
| 6102 | // Since we have proxy, should try to establish tunnel. |
| 6103 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6104 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6105 | "Host: www.example.org:443\r\n" |
| 6106 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6107 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6108 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 6109 | "Host: www.example.org\r\n" |
| 6110 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6111 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6112 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 6113 | "Host: www.example.org\r\n" |
| 6114 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6115 | }; |
| 6116 | |
| 6117 | // The proxy responds to the connect with a 407, using a persistent |
| 6118 | // connection. |
| 6119 | MockRead data_reads1[] = { |
| 6120 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 6121 | |
| 6122 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6123 | MockRead("Content-Length: 1\r\n\r\n"), |
| 6124 | MockRead(SYNCHRONOUS, "1"), |
| 6125 | |
| 6126 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6127 | MockRead("Content-Length: 2\r\n\r\n"), |
| 6128 | MockRead(SYNCHRONOUS, "22"), |
| 6129 | }; |
| 6130 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6131 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6132 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6133 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6134 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6135 | |
| 6136 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6137 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6138 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6139 | |
| 6140 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6142 | |
| 6143 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6145 | |
| 6146 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6147 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 6148 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6149 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6150 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 6151 | |
| 6152 | LoadTimingInfo load_timing_info1; |
| 6153 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 6154 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6155 | |
| 6156 | trans1.reset(); |
| 6157 | |
| 6158 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6159 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6160 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6161 | |
| 6162 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6164 | |
| 6165 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6167 | |
| 6168 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6169 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 6170 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6171 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6172 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 6173 | |
| 6174 | LoadTimingInfo load_timing_info2; |
| 6175 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6176 | TestLoadTimingReused(load_timing_info2); |
| 6177 | |
| 6178 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 6179 | |
| 6180 | trans2.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 6181 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | // 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] | 6185 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6186 | HttpRequestInfo request1; |
| 6187 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6188 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6189 | request1.traffic_annotation = |
| 6190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6191 | |
| 6192 | HttpRequestInfo request2; |
| 6193 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6194 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6195 | request2.traffic_annotation = |
| 6196 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6197 | |
| 6198 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 6199 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6200 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6201 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6202 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6203 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6204 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6205 | |
| 6206 | // Since we have proxy, should try to establish tunnel. |
| 6207 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6208 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6209 | "Host: www.example.org:443\r\n" |
| 6210 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6211 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6212 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 6213 | "Host: www.example.org\r\n" |
| 6214 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6215 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6216 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 6217 | "Host: www.example.org\r\n" |
| 6218 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6219 | }; |
| 6220 | |
| 6221 | // The proxy responds to the connect with a 407, using a persistent |
| 6222 | // connection. |
| 6223 | MockRead data_reads1[] = { |
| 6224 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 6225 | |
| 6226 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6227 | MockRead("Content-Length: 1\r\n\r\n"), |
| 6228 | MockRead(SYNCHRONOUS, "1"), |
| 6229 | |
| 6230 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6231 | MockRead("Content-Length: 2\r\n\r\n"), |
| 6232 | MockRead(SYNCHRONOUS, "22"), |
| 6233 | }; |
| 6234 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6235 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6236 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6237 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6239 | |
| 6240 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6241 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6242 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6243 | |
| 6244 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6245 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6246 | |
| 6247 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6248 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6249 | |
| 6250 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6251 | ASSERT_TRUE(response1); |
| 6252 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6253 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 6254 | |
| 6255 | LoadTimingInfo load_timing_info1; |
| 6256 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 6257 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 6258 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 6259 | |
| 6260 | trans1.reset(); |
| 6261 | |
| 6262 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6263 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6264 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6265 | |
| 6266 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6268 | |
| 6269 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6271 | |
| 6272 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6273 | ASSERT_TRUE(response2); |
| 6274 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6275 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 6276 | |
| 6277 | LoadTimingInfo load_timing_info2; |
| 6278 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6279 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 6280 | |
| 6281 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 6282 | |
| 6283 | trans2.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 6284 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 6285 | } |
| 6286 | |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 6287 | // Make sure that NetworkIsolationKeys are passed down to the proxy layer. |
| 6288 | TEST_F(HttpNetworkTransactionTest, ProxyResolvedWithNetworkIsolationKey) { |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 6289 | const SchemefulSite kSite(GURL("https://foo.test/")); |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 6290 | |
| 6291 | ProxyConfig proxy_config; |
| 6292 | proxy_config.set_auto_detect(true); |
| 6293 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6294 | |
| 6295 | CapturingProxyResolver capturing_proxy_resolver; |
| 6296 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6297 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6298 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 6299 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6300 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6301 | std::make_unique<CapturingProxyResolverFactory>( |
| 6302 | &capturing_proxy_resolver), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 6303 | nullptr, /*quick_check_enabled=*/true); |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 6304 | |
| 6305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6306 | |
| 6307 | // No need to continue with the network request - proxy resolution occurs |
| 6308 | // before establishing a data. |
| 6309 | StaticSocketDataProvider data{base::span<MockRead>(), |
| 6310 | base::span<MockWrite>()}; |
| 6311 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_FAILED)); |
| 6312 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6313 | |
| 6314 | // Run first request until an auth challenge is observed. |
| 6315 | HttpRequestInfo request; |
| 6316 | request.method = "GET"; |
| 6317 | request.url = GURL("http://foo.test/"); |
| 6318 | request.traffic_annotation = |
| 6319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6320 | HttpNetworkTransaction trans(LOWEST, session.get()); |
| 6321 | TestCompletionCallback callback; |
| 6322 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 6323 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_FAILED)); |
| 6324 | } |
| 6325 | |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 6326 | // Test that a failure in resolving the proxy hostname is retrievable. |
| 6327 | TEST_F(HttpNetworkTransactionTest, ProxyHostResolutionFailure) { |
| 6328 | HttpRequestInfo request; |
| 6329 | request.method = "GET"; |
| 6330 | request.url = GURL("http://www.example.org/"); |
| 6331 | request.traffic_annotation = |
| 6332 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6333 | |
| 6334 | RecordingTestNetLog log; |
| 6335 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6336 | session_deps_.proxy_resolution_service = |
| 6337 | ConfiguredProxyResolutionService::CreateFixed( |
| 6338 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 6339 | MockHostResolver* resolver = new MockHostResolver(); |
| 6340 | resolver->rules()->AddSimulatedTimeoutFailure("proxy"); |
| 6341 | session_deps_.net_log = &log; |
| 6342 | session_deps_.host_resolver.reset(resolver); |
| 6343 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 6344 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6345 | TestCompletionCallback callback; |
| 6346 | |
| 6347 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 6348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6349 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_PROXY_CONNECTION_FAILED)); |
| 6350 | |
| 6351 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6352 | ASSERT_TRUE(response); |
| 6353 | EXPECT_THAT(response->resolve_error_info.error, IsError(ERR_DNS_TIMED_OUT)); |
| 6354 | } |
| 6355 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6356 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6357 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6358 | HttpRequestInfo request; |
| 6359 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6360 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6361 | request.traffic_annotation = |
| 6362 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6363 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6364 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6365 | session_deps_.proxy_resolution_service = |
| 6366 | ConfiguredProxyResolutionService::CreateFixed( |
| 6367 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6368 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6369 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6371 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6372 | // Since we have proxy, should use full url |
| 6373 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6374 | MockWrite( |
| 6375 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6376 | "Host: www.example.org\r\n" |
| 6377 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6378 | }; |
| 6379 | |
| 6380 | MockRead data_reads1[] = { |
| 6381 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6382 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6383 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6385 | }; |
| 6386 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6387 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6388 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6389 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6390 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6391 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6392 | ConnectedHandler connected_handler; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6393 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6396 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6397 | trans.SetConnectedCallback(connected_handler.Callback()); |
| 6398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6399 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6401 | |
| 6402 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6404 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6405 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6406 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6407 | TestLoadTimingNotReused(load_timing_info, |
| 6408 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6410 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6411 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6412 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 6413 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6414 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6415 | EXPECT_EQ(200, response->headers->response_code()); |
| 6416 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6417 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6418 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6419 | TransportInfo expected_transport; |
| 6420 | expected_transport.type = TransportType::kProxied; |
| 6421 | expected_transport.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 70); |
| 6422 | EXPECT_THAT(connected_handler.transports(), ElementsAre(expected_transport)); |
| 6423 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6424 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6425 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6426 | } |
| 6427 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6428 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6429 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6430 | HttpRequestInfo request; |
| 6431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6432 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6433 | request.traffic_annotation = |
| 6434 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6435 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6436 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6437 | session_deps_.proxy_resolution_service = |
| 6438 | ConfiguredProxyResolutionService::CreateFixed( |
| 6439 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6440 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6441 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6443 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6444 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6445 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6446 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6447 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6448 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6449 | spdy::SpdySerializedFrame resp( |
| 6450 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6451 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6452 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6453 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6454 | }; |
| 6455 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6456 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6457 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6458 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6459 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6460 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6462 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6463 | ConnectedHandler connected_handler; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6464 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6467 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6468 | trans.SetConnectedCallback(connected_handler.Callback()); |
| 6469 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6470 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6472 | |
| 6473 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6474 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6475 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6476 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6477 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6478 | TestLoadTimingNotReused(load_timing_info, |
| 6479 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6481 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6482 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 6483 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6484 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6485 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6486 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 6487 | TransportInfo expected_transport; |
| 6488 | expected_transport.type = TransportType::kProxied; |
| 6489 | expected_transport.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 70); |
| 6490 | EXPECT_THAT(connected_handler.transports(), ElementsAre(expected_transport)); |
| 6491 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6492 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6493 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6494 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 6495 | } |
| 6496 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6497 | // Verifies that a session which races and wins against the owning transaction |
| 6498 | // (completing prior to host resolution), doesn't fail the transaction. |
| 6499 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6500 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6501 | HttpRequestInfo request; |
| 6502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6503 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6504 | request.traffic_annotation = |
| 6505 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6506 | |
| 6507 | // Configure SPDY proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6508 | session_deps_.proxy_resolution_service = |
| 6509 | ConfiguredProxyResolutionService::CreateFixed( |
| 6510 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6511 | RecordingBoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6512 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6514 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6515 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6516 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6517 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6518 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6519 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6520 | spdy::SpdySerializedFrame resp( |
| 6521 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6522 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6523 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6524 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6525 | }; |
| 6526 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6527 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6528 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 6529 | |
| 6530 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6531 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6533 | |
| 6534 | TestCompletionCallback callback1; |
| 6535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6536 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6537 | |
| 6538 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6539 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 6540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6541 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6543 | |
| 6544 | // Race a session to the proxy, which completes first. |
| 6545 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 6546 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6547 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 6548 | SpdySessionKey::IsProxySession::kTrue, SocketTag(), |
| 6549 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6550 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 6551 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6552 | |
| 6553 | // Unstall the resolution begun by the transaction. |
| 6554 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 6555 | session_deps_.host_resolver->ResolveAllPending(); |
| 6556 | |
| 6557 | EXPECT_FALSE(callback1.have_result()); |
| 6558 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6561 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6562 | ASSERT_TRUE(response); |
| 6563 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6564 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6565 | |
| 6566 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6567 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 6568 | EXPECT_EQ(kUploadData, response_data); |
| 6569 | } |
| 6570 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6571 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6572 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6573 | HttpRequestInfo request; |
| 6574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6575 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6576 | request.traffic_annotation = |
| 6577 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6578 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6579 | // Configure against https proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6580 | session_deps_.proxy_resolution_service = |
| 6581 | ConfiguredProxyResolutionService::CreateFixed( |
| 6582 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6583 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6584 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6586 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6587 | // The first request will be a bare GET, the second request will be a |
| 6588 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6589 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6590 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 6591 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6592 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6593 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6594 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6595 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6596 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 6597 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 6598 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6599 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6600 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6601 | }; |
| 6602 | |
| 6603 | // The first response is a 407 proxy authentication challenge, and the second |
| 6604 | // response will be a 200 response since the second request includes a valid |
| 6605 | // Authorization header. |
| 6606 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 6607 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6608 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6609 | spdy::SpdySerializedFrame resp_authentication( |
| 6610 | spdy_util_.ConstructSpdyReplyError( |
| 6611 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 6612 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6613 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6614 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6615 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6616 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6617 | spdy::SpdySerializedFrame body_data( |
| 6618 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6619 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6620 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6621 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6622 | CreateMockRead(resp_data, 4), |
| 6623 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6624 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6625 | }; |
| 6626 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6627 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6629 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6630 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6631 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6634 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6635 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6636 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6638 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6639 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6640 | |
| 6641 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6642 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6644 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6645 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6646 | ASSERT_TRUE(response); |
| 6647 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6648 | EXPECT_EQ(407, response->headers->response_code()); |
| 6649 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6650 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6651 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6652 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6654 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6656 | |
| 6657 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6658 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6660 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6661 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6662 | ASSERT_TRUE(response_restart); |
| 6663 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6664 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 6665 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6666 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 6667 | } |
| 6668 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6669 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6670 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6671 | HttpRequestInfo request; |
| 6672 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6673 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6674 | request.traffic_annotation = |
| 6675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6676 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6677 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6678 | session_deps_.proxy_resolution_service = |
| 6679 | ConfiguredProxyResolutionService::CreateFixed( |
| 6680 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6681 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6682 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6686 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6687 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6688 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6689 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6690 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6691 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6692 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6693 | const char get[] = |
| 6694 | "GET / HTTP/1.1\r\n" |
| 6695 | "Host: www.example.org\r\n" |
| 6696 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6697 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6698 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6699 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6700 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6701 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6702 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6703 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6704 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6705 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6706 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6707 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6708 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6709 | |
| 6710 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6711 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 6712 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6713 | }; |
| 6714 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6715 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6716 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6717 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 6718 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 6719 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6720 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6721 | }; |
| 6722 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6723 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6724 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6725 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6726 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6727 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6729 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6732 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6734 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6736 | |
| 6737 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6738 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6739 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6740 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6741 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6742 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6745 | ASSERT_TRUE(response); |
| 6746 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6747 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6748 | |
| 6749 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6750 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6751 | EXPECT_EQ("1234567890", response_data); |
| 6752 | } |
| 6753 | |
| 6754 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6755 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 6756 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6757 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6758 | HttpRequestInfo request; |
| 6759 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6760 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6761 | request.traffic_annotation = |
| 6762 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6763 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6764 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6765 | session_deps_.proxy_resolution_service = |
| 6766 | ConfiguredProxyResolutionService::CreateFixed( |
| 6767 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6768 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6769 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6771 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6772 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6773 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6774 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6775 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6776 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6777 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6778 | // fetch https://www.example.org/ via SPDY |
| 6779 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6780 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 6781 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6782 | spdy::SpdySerializedFrame wrapped_get( |
| 6783 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6784 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6785 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6786 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6787 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6788 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6789 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6790 | spdy::SpdySerializedFrame body( |
| 6791 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 6792 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6793 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6794 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6795 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6796 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6797 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6798 | |
| 6799 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6800 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 6801 | CreateMockWrite(window_update_get_resp, 6), |
| 6802 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 6803 | }; |
| 6804 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6805 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6806 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 6807 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6808 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6809 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 6810 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6811 | }; |
| 6812 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6813 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6814 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6815 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6816 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6817 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6819 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6820 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6821 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6823 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6825 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6827 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 6828 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6829 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 6830 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 6831 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6832 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6833 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6834 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6835 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6836 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6837 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6839 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6840 | ASSERT_TRUE(response); |
| 6841 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6842 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6843 | |
| 6844 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6845 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6846 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6847 | } |
| 6848 | |
| 6849 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6850 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6851 | HttpRequestInfo request; |
| 6852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6853 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6854 | request.traffic_annotation = |
| 6855 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6856 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6857 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6858 | session_deps_.proxy_resolution_service = |
| 6859 | ConfiguredProxyResolutionService::CreateFixed( |
| 6860 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 6861 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6862 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6864 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6866 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6867 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6868 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6869 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6870 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6871 | spdy::SpdySerializedFrame get( |
| 6872 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6873 | |
| 6874 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6875 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6876 | }; |
| 6877 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6878 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 6879 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6880 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6881 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6882 | }; |
| 6883 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6884 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6885 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6886 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6887 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6888 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6889 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6890 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6891 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6892 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6894 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6896 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6898 | |
| 6899 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6900 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6901 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 6902 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 6903 | } |
| 6904 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6905 | // 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] | 6906 | // is observed, but does exist by the time auth credentials are provided. In |
| 6907 | // this case, auth and SSL are fully negotated on the second request, but then |
| 6908 | // the socket is discarded to use the shared session. |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6909 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 6910 | ProxyConfig proxy_config; |
| 6911 | proxy_config.set_auto_detect(true); |
| 6912 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6913 | |
| 6914 | CapturingProxyResolver capturing_proxy_resolver; |
| 6915 | capturing_proxy_resolver.set_proxy_server( |
| 6916 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 6917 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 6918 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6919 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6920 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6921 | std::make_unique<CapturingProxyResolverFactory>( |
| 6922 | &capturing_proxy_resolver), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 6923 | nullptr, /*quick_check_enabled=*/true); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6924 | |
| 6925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6926 | |
| 6927 | const char kMyUrl[] = "https://www.example.org/"; |
| 6928 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6929 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6930 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6931 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 6932 | |
| 6933 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6934 | spdy::SpdySerializedFrame get2( |
| 6935 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 6936 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6937 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6938 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 6939 | |
| 6940 | MockWrite auth_challenge_writes[] = { |
| 6941 | MockWrite(ASYNC, 0, |
| 6942 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6943 | "Host: www.example.org:443\r\n" |
| 6944 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6945 | MockWrite(ASYNC, 2, |
| 6946 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6947 | "Host: www.example.org:443\r\n" |
| 6948 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6949 | }; |
| 6950 | |
| 6951 | MockRead auth_challenge_reads[] = { |
| 6952 | MockRead(ASYNC, 1, |
| 6953 | "HTTP/1.1 407 Authentication Required\r\n" |
| 6954 | "Content-Length: 0\r\n" |
| 6955 | "Proxy-Connection: close\r\n" |
| 6956 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 6957 | }; |
| 6958 | |
| 6959 | MockWrite spdy_writes[] = { |
| 6960 | MockWrite(ASYNC, 0, |
| 6961 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6962 | "Host: www.example.org:443\r\n" |
| 6963 | "Proxy-Connection: keep-alive\r\n" |
| 6964 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 6965 | CreateMockWrite(get, 2), |
| 6966 | CreateMockWrite(get2, 5), |
| 6967 | }; |
| 6968 | |
| 6969 | MockRead spdy_reads[] = { |
| 6970 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 6971 | CreateMockRead(get_resp, 3, ASYNC), |
| 6972 | CreateMockRead(body, 4, ASYNC), |
| 6973 | CreateMockRead(get_resp2, 6, ASYNC), |
| 6974 | CreateMockRead(body2, 7, ASYNC), |
| 6975 | |
| 6976 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 6977 | }; |
| 6978 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6979 | MockWrite auth_response_writes_discarded_socket[] = { |
| 6980 | MockWrite(ASYNC, 0, |
| 6981 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6982 | "Host: www.example.org:443\r\n" |
| 6983 | "Proxy-Connection: keep-alive\r\n" |
| 6984 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 6985 | }; |
| 6986 | |
| 6987 | MockRead auth_response_reads_discarded_socket[] = { |
| 6988 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 6989 | }; |
| 6990 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6991 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 6992 | auth_challenge_writes); |
| 6993 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 6994 | |
| 6995 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 6996 | auth_challenge_writes); |
| 6997 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 6998 | |
| 6999 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 7000 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 7001 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 7002 | SequencedSocketData auth_response_discarded_socket( |
| 7003 | auth_response_reads_discarded_socket, |
| 7004 | auth_response_writes_discarded_socket); |
| 7005 | session_deps_.socket_factory->AddSocketDataProvider( |
| 7006 | &auth_response_discarded_socket); |
| 7007 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 7008 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7009 | ssl.next_proto = kProtoHTTP2; |
| 7010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7011 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 7012 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7013 | ssl2.next_proto = kProtoHTTP2; |
| 7014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7015 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 7016 | TestCompletionCallback callback; |
| 7017 | std::string response_data; |
| 7018 | |
| 7019 | // Run first request until an auth challenge is observed. |
| 7020 | HttpRequestInfo request1; |
| 7021 | request1.method = "GET"; |
| 7022 | request1.url = GURL(kMyUrl); |
| 7023 | request1.traffic_annotation = |
| 7024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7025 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 7026 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 7027 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7028 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 7029 | ASSERT_TRUE(response); |
| 7030 | ASSERT_TRUE(response->headers); |
| 7031 | EXPECT_EQ(407, response->headers->response_code()); |
| 7032 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7033 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 7034 | |
| 7035 | // Run second request until an auth challenge is observed. |
| 7036 | HttpRequestInfo request2; |
| 7037 | request2.method = "GET"; |
| 7038 | request2.url = GURL(kMyUrl); |
| 7039 | request2.traffic_annotation = |
| 7040 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7041 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 7042 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 7043 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7044 | response = trans2.GetResponseInfo(); |
| 7045 | ASSERT_TRUE(response); |
| 7046 | ASSERT_TRUE(response->headers); |
| 7047 | EXPECT_EQ(407, response->headers->response_code()); |
| 7048 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7049 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 7050 | |
| 7051 | // Now provide credentials for the first request, and wait for it to complete. |
| 7052 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 7053 | rv = callback.GetResult(rv); |
| 7054 | EXPECT_THAT(rv, IsOk()); |
| 7055 | response = trans1.GetResponseInfo(); |
| 7056 | ASSERT_TRUE(response); |
| 7057 | ASSERT_TRUE(response->headers); |
| 7058 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 7059 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 7060 | EXPECT_EQ(kUploadData, response_data); |
| 7061 | |
| 7062 | // Now provide credentials for the second request. It should notice the |
| 7063 | // existing session, and reuse it. |
| 7064 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 7065 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7066 | response = trans2.GetResponseInfo(); |
| 7067 | ASSERT_TRUE(response); |
| 7068 | ASSERT_TRUE(response->headers); |
| 7069 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 7070 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 7071 | EXPECT_EQ(kUploadData, response_data); |
| 7072 | } |
| 7073 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7074 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 7075 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7076 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7077 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 7078 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7079 | session_deps_.proxy_resolution_service = |
| 7080 | ConfiguredProxyResolutionService::CreateFixed( |
| 7081 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 7082 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7083 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7084 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7085 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7086 | |
| 7087 | HttpRequestInfo request1; |
| 7088 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7089 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7090 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7091 | request1.traffic_annotation = |
| 7092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7093 | |
| 7094 | HttpRequestInfo request2; |
| 7095 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7096 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7097 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7098 | request2.traffic_annotation = |
| 7099 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7100 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7101 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7102 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7103 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7104 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7105 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7106 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7107 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7108 | // Fetch https://www.example.org/ via HTTP. |
| 7109 | const char get1[] = |
| 7110 | "GET / HTTP/1.1\r\n" |
| 7111 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7112 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7113 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7114 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7115 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 7116 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7117 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7118 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7119 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7120 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7121 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7122 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7123 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7124 | // CONNECT to mail.example.org:443 via SPDY. |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 7125 | spdy::Http2HeaderBlock connect2_block; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7126 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 7127 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 7128 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7129 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7130 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 7131 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7132 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7133 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7134 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7135 | // Fetch https://mail.example.org/ via HTTP. |
| 7136 | const char get2[] = |
| 7137 | "GET / HTTP/1.1\r\n" |
| 7138 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7139 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7140 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7141 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7142 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 7143 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7144 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7145 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7146 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7147 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7148 | |
| 7149 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7150 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 7151 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7152 | }; |
| 7153 | |
| 7154 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7155 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 7156 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 7157 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 7158 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 7159 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 7160 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 7161 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7162 | }; |
| 7163 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7164 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7165 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7166 | |
| 7167 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7168 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7170 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7172 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7173 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7174 | |
| 7175 | TestCompletionCallback callback; |
| 7176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7178 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7179 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7180 | |
| 7181 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7182 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7183 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 7184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7185 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7186 | ASSERT_TRUE(response); |
| 7187 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7188 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7189 | |
| 7190 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 7191 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7192 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7193 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7195 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7196 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7197 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7198 | |
| 7199 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7200 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7201 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 7202 | // to be created, so the socket's load timing looks like a fresh connection. |
| 7203 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 7204 | |
| 7205 | // The requests should have different IDs, since they each are using their own |
| 7206 | // separate stream. |
| 7207 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 7208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7209 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7210 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 7214 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7215 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7216 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 7217 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7218 | session_deps_.proxy_resolution_service = |
| 7219 | ConfiguredProxyResolutionService::CreateFixed( |
| 7220 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 7221 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7222 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7223 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7224 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7225 | |
| 7226 | HttpRequestInfo request1; |
| 7227 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7228 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7229 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7230 | request1.traffic_annotation = |
| 7231 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7232 | |
| 7233 | HttpRequestInfo request2; |
| 7234 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7235 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7236 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7237 | request2.traffic_annotation = |
| 7238 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7239 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7240 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7241 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7242 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7243 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7244 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7245 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7246 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7247 | // Fetch https://www.example.org/ via HTTP. |
| 7248 | const char get1[] = |
| 7249 | "GET / HTTP/1.1\r\n" |
| 7250 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7251 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7252 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7253 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7254 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 7255 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7256 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7257 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7258 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7259 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7260 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7261 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7262 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7263 | // Fetch https://www.example.org/2 via HTTP. |
| 7264 | const char get2[] = |
| 7265 | "GET /2 HTTP/1.1\r\n" |
| 7266 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7267 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7268 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7269 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7270 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 7271 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7272 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7273 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7274 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 7275 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7276 | |
| 7277 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7278 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 7279 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7280 | }; |
| 7281 | |
| 7282 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7283 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 7284 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 7285 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7286 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 7287 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7288 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7289 | }; |
| 7290 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7291 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7292 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7293 | |
| 7294 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7295 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7297 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7299 | |
| 7300 | TestCompletionCallback callback; |
| 7301 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7302 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7303 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7304 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7306 | |
| 7307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7308 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7309 | |
| 7310 | LoadTimingInfo load_timing_info; |
| 7311 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7312 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 7313 | |
| 7314 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7315 | ASSERT_TRUE(response); |
| 7316 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7317 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7318 | |
| 7319 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 7320 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7321 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7322 | trans.reset(); |
| 7323 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7324 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7325 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7326 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7327 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7328 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7329 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7330 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7331 | |
| 7332 | LoadTimingInfo load_timing_info2; |
| 7333 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 7334 | TestLoadTimingReused(load_timing_info2); |
| 7335 | |
| 7336 | // The requests should have the same ID. |
| 7337 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 7338 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7339 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7340 | } |
| 7341 | |
| 7342 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 7343 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7344 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7345 | // Configure against https proxy server "proxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7346 | session_deps_.proxy_resolution_service = |
| 7347 | ConfiguredProxyResolutionService::CreateFixed( |
| 7348 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 7349 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7350 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7351 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7352 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7353 | |
| 7354 | HttpRequestInfo request1; |
| 7355 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7356 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7357 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7358 | request1.traffic_annotation = |
| 7359 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7360 | |
| 7361 | HttpRequestInfo request2; |
| 7362 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7363 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7364 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7365 | request2.traffic_annotation = |
| 7366 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7367 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7368 | // http://www.example.org/ |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 7369 | spdy::Http2HeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7370 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7371 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7372 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7373 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7374 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7375 | spdy::SpdySerializedFrame body1( |
| 7376 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7377 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7378 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7379 | // http://mail.example.org/ |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 7380 | spdy::Http2HeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7381 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7382 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7383 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7384 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7385 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7386 | spdy::SpdySerializedFrame body2( |
| 7387 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7388 | |
| 7389 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7390 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7391 | }; |
| 7392 | |
| 7393 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7394 | CreateMockRead(get_resp1, 1, ASYNC), |
| 7395 | CreateMockRead(body1, 2, ASYNC), |
| 7396 | CreateMockRead(get_resp2, 4, ASYNC), |
| 7397 | CreateMockRead(body2, 5, ASYNC), |
| 7398 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7399 | }; |
| 7400 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7401 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7402 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7403 | |
| 7404 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7405 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7407 | |
| 7408 | TestCompletionCallback callback; |
| 7409 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7410 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7411 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7412 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7413 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7414 | |
| 7415 | LoadTimingInfo load_timing_info; |
| 7416 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7417 | TestLoadTimingNotReused(load_timing_info, |
| 7418 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7419 | |
| 7420 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7421 | ASSERT_TRUE(response); |
| 7422 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 7423 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7424 | |
| 7425 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 7426 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7427 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 7428 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7429 | // Delete the first request, so the second one can reuse the socket. |
| 7430 | trans.reset(); |
| 7431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7432 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7433 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7434 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7435 | |
| 7436 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7437 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7438 | TestLoadTimingReused(load_timing_info2); |
| 7439 | |
| 7440 | // The requests should have the same ID. |
| 7441 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 7442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7443 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 7444 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 7445 | } |
| 7446 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7447 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 7448 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 7449 | // would break socket pool isolation. |
| 7450 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 7451 | ProxyConfig proxy_config; |
| 7452 | proxy_config.set_auto_detect(true); |
| 7453 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 7454 | |
| 7455 | CapturingProxyResolver capturing_proxy_resolver; |
| 7456 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7457 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7458 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 7459 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 7460 | std::make_unique<CapturingProxyResolverFactory>( |
| 7461 | &capturing_proxy_resolver), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 7462 | nullptr, /*quick_check_enabled=*/true); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7463 | |
| 7464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7465 | |
| 7466 | SpdyTestUtil spdy_util1; |
| 7467 | // CONNECT to www.example.org:443 via HTTP/2. |
| 7468 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7469 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7470 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7471 | // fetch https://www.example.org/ via HTTP/2. |
| 7472 | const char kMyUrl[] = "https://www.example.org/"; |
| 7473 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 7474 | spdy::SpdySerializedFrame wrapped_get( |
| 7475 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 7476 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7477 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7478 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 7479 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7480 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 7481 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 7482 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 7483 | spdy::SpdySerializedFrame wrapped_body( |
| 7484 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 7485 | spdy::SpdySerializedFrame window_update_get_resp( |
| 7486 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 7487 | spdy::SpdySerializedFrame window_update_body( |
| 7488 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 7489 | |
| 7490 | MockWrite spdy_writes1[] = { |
| 7491 | CreateMockWrite(connect, 0), |
| 7492 | CreateMockWrite(wrapped_get, 2), |
| 7493 | CreateMockWrite(window_update_get_resp, 6), |
| 7494 | CreateMockWrite(window_update_body, 7), |
| 7495 | }; |
| 7496 | |
| 7497 | MockRead spdy_reads1[] = { |
| 7498 | CreateMockRead(conn_resp, 1, ASYNC), |
| 7499 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 7500 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 7501 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 7502 | MockRead(ASYNC, 0, 8), |
| 7503 | }; |
| 7504 | |
| 7505 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 7506 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 7507 | |
| 7508 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 7509 | // a new pipe. |
| 7510 | SpdyTestUtil spdy_util2; |
| 7511 | spdy::SpdySerializedFrame req( |
| 7512 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 7513 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 7514 | |
| 7515 | spdy::SpdySerializedFrame resp( |
| 7516 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7517 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 7518 | MockRead spdy_reads2[] = { |
| 7519 | CreateMockRead(resp, 1), |
| 7520 | CreateMockRead(data, 2), |
| 7521 | MockRead(ASYNC, 0, 3), |
| 7522 | }; |
| 7523 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 7524 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 7525 | |
| 7526 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7527 | ssl.next_proto = kProtoHTTP2; |
| 7528 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7529 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7530 | ssl2.next_proto = kProtoHTTP2; |
| 7531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7532 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7533 | ssl3.next_proto = kProtoHTTP2; |
| 7534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7535 | |
| 7536 | TestCompletionCallback callback; |
| 7537 | std::string response_data; |
| 7538 | |
| 7539 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 7540 | capturing_proxy_resolver.set_proxy_server( |
| 7541 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 7542 | HttpRequestInfo request1; |
| 7543 | request1.method = "GET"; |
| 7544 | request1.url = GURL("https://www.example.org/"); |
| 7545 | request1.traffic_annotation = |
| 7546 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7547 | |
| 7548 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 7549 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 7550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7551 | |
| 7552 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 7553 | base::RunLoop().RunUntilIdle(); |
| 7554 | // Now allow the read of the response to complete. |
| 7555 | spdy_data1.Resume(); |
| 7556 | rv = callback.WaitForResult(); |
| 7557 | EXPECT_THAT(rv, IsOk()); |
| 7558 | |
| 7559 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 7560 | ASSERT_TRUE(response); |
| 7561 | ASSERT_TRUE(response->headers); |
| 7562 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 7563 | |
| 7564 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 7565 | EXPECT_EQ(kUploadData, response_data); |
| 7566 | RunUntilIdle(); |
| 7567 | |
| 7568 | // Make a direct HTTP/2 request to proxy:70. |
| 7569 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 7570 | HttpRequestInfo request2; |
| 7571 | request2.method = "GET"; |
| 7572 | request2.url = GURL("https://proxy:70/"); |
| 7573 | request2.traffic_annotation = |
| 7574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7575 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 7576 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 7577 | NetLogWithSource())), |
| 7578 | IsOk()); |
| 7579 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 7580 | } |
| 7581 | |
| 7582 | // Same as above, but reverse request order, since the code to check for an |
| 7583 | // existing session is different for tunnels and direct connections. |
| 7584 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 7585 | // Configure against https proxy server "myproxy:80". |
| 7586 | ProxyConfig proxy_config; |
| 7587 | proxy_config.set_auto_detect(true); |
| 7588 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 7589 | |
| 7590 | CapturingProxyResolver capturing_proxy_resolver; |
| 7591 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7592 | std::make_unique<ConfiguredProxyResolutionService>( |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7593 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 7594 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 7595 | std::make_unique<CapturingProxyResolverFactory>( |
| 7596 | &capturing_proxy_resolver), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 7597 | nullptr, /*quick_check_enabled=*/true); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7598 | |
| 7599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7600 | // Fetch https://proxy:70/ via HTTP/2. |
| 7601 | SpdyTestUtil spdy_util1; |
| 7602 | spdy::SpdySerializedFrame req( |
| 7603 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 7604 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 7605 | |
| 7606 | spdy::SpdySerializedFrame resp( |
| 7607 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7608 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 7609 | MockRead spdy_reads1[] = { |
| 7610 | CreateMockRead(resp, 1), |
| 7611 | CreateMockRead(data, 2), |
| 7612 | MockRead(ASYNC, 0, 3), |
| 7613 | }; |
| 7614 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 7615 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 7616 | |
| 7617 | SpdyTestUtil spdy_util2; |
| 7618 | // CONNECT to www.example.org:443 via HTTP/2. |
| 7619 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 7620 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 7621 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 7622 | // fetch https://www.example.org/ via HTTP/2. |
| 7623 | const char kMyUrl[] = "https://www.example.org/"; |
| 7624 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 7625 | spdy::SpdySerializedFrame wrapped_get( |
| 7626 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 7627 | spdy::SpdySerializedFrame conn_resp( |
| 7628 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7629 | spdy::SpdySerializedFrame get_resp( |
| 7630 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7631 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 7632 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 7633 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 7634 | spdy::SpdySerializedFrame wrapped_body( |
| 7635 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 7636 | spdy::SpdySerializedFrame window_update_get_resp( |
| 7637 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 7638 | spdy::SpdySerializedFrame window_update_body( |
| 7639 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 7640 | |
| 7641 | MockWrite spdy_writes2[] = { |
| 7642 | CreateMockWrite(connect, 0), |
| 7643 | CreateMockWrite(wrapped_get, 2), |
| 7644 | CreateMockWrite(window_update_get_resp, 6), |
| 7645 | CreateMockWrite(window_update_body, 7), |
| 7646 | }; |
| 7647 | |
| 7648 | MockRead spdy_reads2[] = { |
| 7649 | CreateMockRead(conn_resp, 1, ASYNC), |
| 7650 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 7651 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 7652 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 7653 | MockRead(ASYNC, 0, 8), |
| 7654 | }; |
| 7655 | |
| 7656 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 7657 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 7658 | |
| 7659 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7660 | ssl.next_proto = kProtoHTTP2; |
| 7661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7662 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7663 | ssl2.next_proto = kProtoHTTP2; |
| 7664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7665 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7666 | ssl3.next_proto = kProtoHTTP2; |
| 7667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7668 | |
| 7669 | TestCompletionCallback callback; |
| 7670 | std::string response_data; |
| 7671 | |
| 7672 | // Make a direct HTTP/2 request to proxy:70. |
| 7673 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 7674 | HttpRequestInfo request1; |
| 7675 | request1.method = "GET"; |
| 7676 | request1.url = GURL("https://proxy:70/"); |
| 7677 | request1.traffic_annotation = |
| 7678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7679 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 7680 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 7681 | NetLogWithSource())), |
| 7682 | IsOk()); |
| 7683 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 7684 | RunUntilIdle(); |
| 7685 | |
| 7686 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 7687 | capturing_proxy_resolver.set_proxy_server( |
| 7688 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 7689 | HttpRequestInfo request2; |
| 7690 | request2.method = "GET"; |
| 7691 | request2.url = GURL("https://www.example.org/"); |
| 7692 | request2.traffic_annotation = |
| 7693 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7694 | |
| 7695 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 7696 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 7697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7698 | |
| 7699 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 7700 | base::RunLoop().RunUntilIdle(); |
| 7701 | // Now allow the read of the response to complete. |
| 7702 | spdy_data2.Resume(); |
| 7703 | rv = callback.WaitForResult(); |
| 7704 | EXPECT_THAT(rv, IsOk()); |
| 7705 | |
| 7706 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 7707 | ASSERT_TRUE(response2); |
| 7708 | ASSERT_TRUE(response2->headers); |
| 7709 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 7710 | |
| 7711 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 7712 | EXPECT_EQ(kUploadData, response_data); |
| 7713 | } |
| 7714 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7715 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7716 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7717 | HttpRequestInfo request; |
| 7718 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7719 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7720 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 7721 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7722 | request.traffic_annotation = |
| 7723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7724 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7725 | // Configure against https proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7726 | session_deps_.proxy_resolution_service = |
| 7727 | ConfiguredProxyResolutionService::CreateFixed( |
| 7728 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 7729 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7730 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7732 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7733 | // Since we have proxy, should use full url |
| 7734 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7735 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 7736 | "Host: www.example.org\r\n" |
| 7737 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7739 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7740 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7741 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 7742 | "Host: www.example.org\r\n" |
| 7743 | "Proxy-Connection: keep-alive\r\n" |
| 7744 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7745 | }; |
| 7746 | |
| 7747 | // The proxy responds to the GET with a 407, using a persistent |
| 7748 | // connection. |
| 7749 | MockRead data_reads1[] = { |
| 7750 | // No credentials. |
| 7751 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7752 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7753 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 7754 | MockRead("Content-Length: 0\r\n\r\n"), |
| 7755 | |
| 7756 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7757 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7758 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7759 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7760 | }; |
| 7761 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7762 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7763 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7764 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7765 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7766 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7767 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7771 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7773 | |
| 7774 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7775 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7776 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7777 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7778 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7779 | TestLoadTimingNotReused(load_timing_info, |
| 7780 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7782 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7783 | ASSERT_TRUE(response); |
| 7784 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7785 | EXPECT_EQ(407, response->headers->response_code()); |
| 7786 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7787 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 7788 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7790 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7792 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7794 | |
| 7795 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7797 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7798 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7799 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 7800 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 7801 | TestLoadTimingReused(load_timing_info); |
| 7802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7803 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7804 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7805 | |
| 7806 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7807 | EXPECT_EQ(200, response->headers->response_code()); |
| 7808 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7809 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 7810 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7811 | |
| 7812 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7813 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7814 | } |
| 7815 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7816 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7817 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7818 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7819 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7820 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7821 | request.traffic_annotation = |
| 7822 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7823 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7824 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 7825 | session_deps_.proxy_resolution_service = |
| 7826 | ConfiguredProxyResolutionService::CreateFixed( |
| 7827 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7829 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7830 | // Since we have proxy, should try to establish tunnel. |
| 7831 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7832 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7833 | "Host: www.example.org:443\r\n" |
| 7834 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7835 | }; |
| 7836 | |
| 7837 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7838 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 7839 | // No response body because the test stops reading here. |
| 7840 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7841 | }; |
| 7842 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7843 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7846 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7847 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7849 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7850 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7851 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7852 | |
| 7853 | rv = callback.WaitForResult(); |
| 7854 | EXPECT_EQ(expected_status, rv); |
| 7855 | } |
| 7856 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7857 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 7858 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7859 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7860 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7861 | } |
| 7862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7863 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7864 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 7865 | } |
| 7866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7867 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7868 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 7869 | } |
| 7870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7871 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7872 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 7873 | } |
| 7874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7875 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7876 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 7877 | } |
| 7878 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7879 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7880 | ConnectStatusHelper( |
| 7881 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 7882 | } |
| 7883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7885 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 7886 | } |
| 7887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7889 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 7890 | } |
| 7891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7893 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 7894 | } |
| 7895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7896 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7897 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 7898 | } |
| 7899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7901 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 7902 | } |
| 7903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7905 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 7906 | } |
| 7907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7909 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 7910 | } |
| 7911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7912 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7913 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 7914 | } |
| 7915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7916 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7917 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 7918 | } |
| 7919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7920 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7921 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 7922 | } |
| 7923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7924 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7925 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 7926 | } |
| 7927 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7928 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 7929 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 7930 | } |
| 7931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7932 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7933 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 7934 | } |
| 7935 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7936 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7937 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 7938 | } |
| 7939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7940 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7941 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 7942 | } |
| 7943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7944 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7945 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 7946 | } |
| 7947 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7948 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7949 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 7950 | } |
| 7951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7952 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7953 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 7954 | } |
| 7955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7956 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7957 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 7958 | } |
| 7959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7960 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7961 | ConnectStatusHelperWithExpectedStatus( |
| 7962 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 7963 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7964 | } |
| 7965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7966 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7967 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 7968 | } |
| 7969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7970 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7971 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 7972 | } |
| 7973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7974 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7975 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 7976 | } |
| 7977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7978 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7979 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 7980 | } |
| 7981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7982 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7983 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 7984 | } |
| 7985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7986 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7987 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 7988 | } |
| 7989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7990 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7991 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 7992 | } |
| 7993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7994 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7995 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 7996 | } |
| 7997 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7998 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7999 | ConnectStatusHelper( |
| 8000 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 8001 | } |
| 8002 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8003 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8004 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 8005 | } |
| 8006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8007 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8008 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 8009 | } |
| 8010 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8011 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8012 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 8013 | } |
| 8014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8015 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8016 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 8017 | } |
| 8018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8019 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8020 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 8021 | } |
| 8022 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8023 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8024 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 8025 | } |
| 8026 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8027 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 8028 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 8029 | } |
| 8030 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8031 | // Test the flow when both the proxy server AND origin server require |
| 8032 | // authentication. Again, this uses basic auth for both since that is |
| 8033 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8034 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8035 | HttpRequestInfo request; |
| 8036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8037 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8038 | request.traffic_annotation = |
| 8039 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8040 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8041 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 8042 | session_deps_.proxy_resolution_service = |
| 8043 | ConfiguredProxyResolutionService::CreateFixed( |
| 8044 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8045 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8047 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8048 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8049 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8050 | MockWrite( |
| 8051 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 8052 | "Host: www.example.org\r\n" |
| 8053 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8054 | }; |
| 8055 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8056 | MockRead data_reads1[] = { |
| 8057 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 8058 | // Give a couple authenticate options (only the middle one is actually |
| 8059 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 8060 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8061 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8062 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 8063 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8064 | // Large content-length -- won't matter, as connection will be reset. |
| 8065 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8066 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8067 | }; |
| 8068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8069 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8070 | // request we should be issuing -- the final header line contains the |
| 8071 | // proxy's credentials. |
| 8072 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8073 | MockWrite( |
| 8074 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 8075 | "Host: www.example.org\r\n" |
| 8076 | "Proxy-Connection: keep-alive\r\n" |
| 8077 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8078 | }; |
| 8079 | |
| 8080 | // Now the proxy server lets the request pass through to origin server. |
| 8081 | // The origin server responds with a 401. |
| 8082 | MockRead data_reads2[] = { |
| 8083 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8084 | // Note: We are using the same realm-name as the proxy server. This is |
| 8085 | // completely valid, as realms are unique across hosts. |
| 8086 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8087 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8088 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8089 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8090 | }; |
| 8091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8092 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8093 | // the credentials for both the proxy and origin server. |
| 8094 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8095 | MockWrite( |
| 8096 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 8097 | "Host: www.example.org\r\n" |
| 8098 | "Proxy-Connection: keep-alive\r\n" |
| 8099 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 8100 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8101 | }; |
| 8102 | |
| 8103 | // Lastly we get the desired content. |
| 8104 | MockRead data_reads3[] = { |
| 8105 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8106 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8107 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8108 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8109 | }; |
| 8110 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8111 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8112 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8113 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8114 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8115 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8116 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8118 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8119 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8120 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8121 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8122 | |
| 8123 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8124 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8126 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8127 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8128 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8129 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8130 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8132 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8134 | |
| 8135 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8138 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8139 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8140 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8142 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8144 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8145 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8147 | |
| 8148 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8149 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8151 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8152 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8153 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 8154 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8155 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8156 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 8157 | // can't hook into its internals to cause it to generate predictable NTLM |
| 8158 | // authorization headers. |
| 8159 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8160 | // The NTLM authentication unit tests are based on known test data from the |
| 8161 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 8162 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 8163 | // for the implementation and testing of the protocol. |
| 8164 | // |
| 8165 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8166 | |
| 8167 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8168 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8169 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8170 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8171 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8172 | request.traffic_annotation = |
| 8173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8174 | |
| 8175 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 8176 | // to other auth schemes. |
| 8177 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8178 | |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8179 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8180 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8181 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8182 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8183 | // Generate the NTLM messages based on known test data. |
| 8184 | std::string negotiate_msg; |
| 8185 | std::string challenge_msg; |
| 8186 | std::string authenticate_msg; |
| 8187 | base::Base64Encode( |
| 8188 | base::StringPiece( |
| 8189 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8190 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8191 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8192 | base::Base64Encode( |
| 8193 | base::StringPiece( |
| 8194 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8195 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8196 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8197 | base::Base64Encode( |
| 8198 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8199 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8200 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8201 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8202 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8203 | &authenticate_msg); |
| 8204 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8205 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8206 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 8207 | "Host: server\r\n" |
| 8208 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8209 | }; |
| 8210 | |
| 8211 | MockRead data_reads1[] = { |
| 8212 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 8213 | // Negotiate and NTLM are often requested together. However, we only want |
| 8214 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 8215 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8216 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 8217 | MockRead("Connection: close\r\n"), |
| 8218 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 8219 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8220 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8221 | }; |
| 8222 | |
| 8223 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8224 | // After restarting with a null identity, this is the |
| 8225 | // request we should be issuing -- the final header line contains a Type |
| 8226 | // 1 message. |
| 8227 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8228 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8229 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8230 | "Authorization: NTLM "), |
| 8231 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8233 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8234 | // (using correct credentials). The second request continues on the |
| 8235 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8236 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8237 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8238 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8239 | "Authorization: NTLM "), |
| 8240 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8241 | }; |
| 8242 | |
| 8243 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8244 | // The origin server responds with a Type 2 message. |
| 8245 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8246 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8247 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8248 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8249 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8250 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8251 | // Lastly we get the desired content. |
| 8252 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8253 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 8254 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8255 | }; |
| 8256 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8257 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8258 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8259 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8260 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8261 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8262 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 8263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8264 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 8265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 8266 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8267 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8270 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8271 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8272 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8273 | |
| 8274 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8275 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8277 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8279 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8280 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8281 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8283 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8284 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8285 | rv = trans.RestartWithAuth( |
| 8286 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8287 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8289 | |
| 8290 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8291 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8293 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8295 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8296 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8297 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8299 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8301 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8302 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8303 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8304 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8305 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8307 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8308 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8309 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8310 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 8311 | |
| 8312 | std::string response_data; |
| 8313 | rv = ReadTransaction(&trans, &response_data); |
| 8314 | EXPECT_THAT(rv, IsOk()); |
| 8315 | EXPECT_EQ("Please Login\r\n", response_data); |
| 8316 | |
| 8317 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 8318 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 8319 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 8320 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 8321 | } |
| 8322 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8323 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8324 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8325 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8326 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8327 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8328 | request.traffic_annotation = |
| 8329 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8330 | |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8331 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8332 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8334 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8335 | // Generate the NTLM messages based on known test data. |
| 8336 | std::string negotiate_msg; |
| 8337 | std::string challenge_msg; |
| 8338 | std::string authenticate_msg; |
| 8339 | base::Base64Encode( |
| 8340 | base::StringPiece( |
| 8341 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8342 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8343 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8344 | base::Base64Encode( |
| 8345 | base::StringPiece( |
| 8346 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8347 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8348 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8349 | base::Base64Encode( |
| 8350 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8351 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8352 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8353 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8354 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8355 | &authenticate_msg); |
| 8356 | |
| 8357 | // The authenticate message when |kWrongPassword| is sent. |
| 8358 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8359 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 8360 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 8361 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 8362 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 8363 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 8364 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8365 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8366 | // Sanity check that it's the same length as the correct authenticate message |
| 8367 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8368 | ASSERT_EQ(authenticate_msg.length(), |
| 8369 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8370 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8371 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8372 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8373 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 8374 | "Host: server\r\n" |
| 8375 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8376 | }; |
| 8377 | |
| 8378 | MockRead data_reads1[] = { |
| 8379 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 8380 | // Negotiate and NTLM are often requested together. However, we only want |
| 8381 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 8382 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8383 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 8384 | MockRead("Connection: close\r\n"), |
| 8385 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 8386 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8387 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8388 | }; |
| 8389 | |
| 8390 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8391 | // After restarting with a null identity, this is the |
| 8392 | // request we should be issuing -- the final header line contains a Type |
| 8393 | // 1 message. |
| 8394 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8395 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8396 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8397 | "Authorization: NTLM "), |
| 8398 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8400 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8401 | // (using incorrect credentials). The second request continues on the |
| 8402 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8403 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8404 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8405 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8406 | "Authorization: NTLM "), |
| 8407 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8408 | }; |
| 8409 | |
| 8410 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8411 | // The origin server responds with a Type 2 message. |
| 8412 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 8413 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8414 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 8415 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8416 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8417 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8418 | // Wrong password. |
| 8419 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 8420 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 8421 | MockRead("Content-Length: 42\r\n"), |
| 8422 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8423 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8424 | }; |
| 8425 | |
| 8426 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8427 | // After restarting with a null identity, this is the |
| 8428 | // request we should be issuing -- the final header line contains a Type |
| 8429 | // 1 message. |
| 8430 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8431 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8432 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8433 | "Authorization: NTLM "), |
| 8434 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8436 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 8437 | // (the credentials for the origin server). The second request continues |
| 8438 | // on the same connection. |
| 8439 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8440 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8441 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8442 | "Authorization: NTLM "), |
| 8443 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8444 | }; |
| 8445 | |
| 8446 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8447 | // The origin server responds with a Type 2 message. |
| 8448 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8449 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8450 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8451 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8452 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8453 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8454 | // Lastly we get the desired content. |
| 8455 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8456 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 8457 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8458 | }; |
| 8459 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8460 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8461 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8462 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8463 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8464 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8465 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8466 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8467 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 8468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8469 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 8470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 8471 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 8472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 8473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8474 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8475 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 8477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8478 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8480 | |
| 8481 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8484 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8486 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8487 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8488 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8490 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8491 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8492 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8493 | rv = trans.RestartWithAuth( |
| 8494 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 8495 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8496 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8497 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8498 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8499 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8500 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8501 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8502 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8503 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8505 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8506 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8507 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8509 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8510 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8511 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8513 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8514 | |
| 8515 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8516 | rv = trans.RestartWithAuth( |
| 8517 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8518 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8520 | |
| 8521 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8522 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8524 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8526 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 8527 | |
| 8528 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8529 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8531 | |
| 8532 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8533 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8535 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8536 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8537 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 8538 | |
| 8539 | std::string response_data; |
| 8540 | rv = ReadTransaction(&trans, &response_data); |
| 8541 | EXPECT_THAT(rv, IsOk()); |
| 8542 | EXPECT_EQ("Please Login\r\n", response_data); |
| 8543 | |
| 8544 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 8545 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 8546 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 8547 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 8548 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 8549 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8550 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8551 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 8552 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 8553 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8554 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8555 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8556 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8557 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8558 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8559 | |
| 8560 | HttpRequestInfo request; |
| 8561 | request.method = "GET"; |
| 8562 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8563 | request.traffic_annotation = |
| 8564 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8565 | |
| 8566 | // First request without credentials. |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 8567 | spdy::Http2HeaderBlock request_headers0( |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8568 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 8569 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8570 | 1, std::move(request_headers0), LOWEST, true)); |
| 8571 | |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 8572 | spdy::Http2HeaderBlock response_headers0; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8573 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8574 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8575 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8576 | 1, std::move(response_headers0), true)); |
| 8577 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8578 | // Stream 1 is closed. |
| 8579 | spdy_util_.UpdateWithStreamDestruction(1); |
| 8580 | |
| 8581 | // Generate the NTLM messages based on known test data. |
| 8582 | std::string negotiate_msg; |
| 8583 | std::string challenge_msg; |
| 8584 | std::string authenticate_msg; |
| 8585 | base::Base64Encode( |
| 8586 | base::StringPiece( |
| 8587 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8588 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8589 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8590 | base::Base64Encode( |
| 8591 | base::StringPiece( |
| 8592 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8593 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8594 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8595 | base::Base64Encode( |
| 8596 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 8597 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8598 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8599 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8600 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8601 | &authenticate_msg); |
| 8602 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 8603 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 8604 | MockRead reads0[] = {CreateMockRead(resp, 1), |
| 8605 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8606 | |
| 8607 | // Retry yet again using HTTP/1.1. |
| 8608 | MockWrite writes1[] = { |
| 8609 | // After restarting with a null identity, this is the |
| 8610 | // request we should be issuing -- the final header line contains a Type |
| 8611 | // 1 message. |
| 8612 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8613 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8614 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8615 | "Authorization: NTLM "), |
| 8616 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8617 | |
| 8618 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 8619 | // (the credentials for the origin server). The second request continues |
| 8620 | // on the same connection. |
| 8621 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 8622 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8623 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8624 | "Authorization: NTLM "), |
| 8625 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8626 | }; |
| 8627 | |
| 8628 | MockRead reads1[] = { |
| 8629 | // The origin server responds with a Type 2 message. |
| 8630 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8631 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 8632 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8633 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8634 | MockRead("You are not authorized to view this page\r\n"), |
| 8635 | |
| 8636 | // Lastly we get the desired content. |
| 8637 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8638 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8639 | 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] | 8640 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8641 | SequencedSocketData data0(reads0, writes0); |
| 8642 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8643 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 8644 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8645 | |
| 8646 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 8647 | ssl0.next_proto = kProtoHTTP2; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 8648 | ssl0.next_protos_expected_in_ssl_config = |
| 8649 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8650 | SSLSocketDataProvider ssl1(ASYNC, OK); |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 8651 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 8652 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 8654 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8655 | |
| 8656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8657 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8658 | |
| 8659 | TestCompletionCallback callback1; |
| 8660 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 8661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8662 | |
| 8663 | rv = callback1.WaitForResult(); |
| 8664 | EXPECT_THAT(rv, IsOk()); |
| 8665 | |
| 8666 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 8667 | |
| 8668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8669 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8670 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8671 | |
| 8672 | TestCompletionCallback callback2; |
| 8673 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 8674 | rv = trans.RestartWithAuth( |
| 8675 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8676 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8678 | |
| 8679 | rv = callback2.WaitForResult(); |
| 8680 | EXPECT_THAT(rv, IsOk()); |
| 8681 | |
| 8682 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 8683 | |
| 8684 | response = trans.GetResponseInfo(); |
| 8685 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8686 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8687 | |
| 8688 | TestCompletionCallback callback3; |
| 8689 | |
| 8690 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 8691 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8692 | |
| 8693 | rv = callback3.WaitForResult(); |
| 8694 | EXPECT_THAT(rv, IsOk()); |
| 8695 | |
| 8696 | response = trans.GetResponseInfo(); |
| 8697 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8698 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 8699 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 8700 | |
| 8701 | std::string response_data; |
| 8702 | rv = ReadTransaction(&trans, &response_data); |
| 8703 | EXPECT_THAT(rv, IsOk()); |
| 8704 | EXPECT_EQ("Please Login\r\n", response_data); |
| 8705 | |
| 8706 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 8707 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 8708 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 8709 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 8710 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8711 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8712 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 8713 | |
| 8714 | // Variant of above test using WebSockets. |
| 8715 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2WithWebsockets) { |
| 8716 | const GURL kInitialUrl("https://server/"); |
| 8717 | const GURL kWebSocketUrl("wss://server/"); |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8718 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8719 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 8720 | |
| 8721 | // Initial request establishes an H2 connection, which will then be reused for |
| 8722 | // WebSockets. This is needed since WebSockets will reuse H2 connections, but |
| 8723 | // it won't create a new one. |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 8724 | spdy::Http2HeaderBlock initial_request_headers( |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8725 | spdy_util_.ConstructGetHeaderBlock(kInitialUrl.spec())); |
| 8726 | spdy::SpdySerializedFrame initial_request(spdy_util_.ConstructSpdyHeaders( |
| 8727 | 1, std::move(initial_request_headers), DEFAULT_PRIORITY, true)); |
| 8728 | spdy::SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 8729 | |
| 8730 | // Settings frame, indicating WebSockets is supported. |
| 8731 | spdy::SettingsMap settings; |
| 8732 | settings[spdy::SETTINGS_ENABLE_CONNECT_PROTOCOL] = 1; |
| 8733 | spdy::SpdySerializedFrame settings_frame( |
| 8734 | spdy_util_.ConstructSpdySettings(settings)); |
| 8735 | |
| 8736 | // Response headers for first request. Body is never received, but that |
| 8737 | // shouldn't matter for the purposes of this test. |
| 8738 | spdy::SpdySerializedFrame initial_response( |
| 8739 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 8740 | |
| 8741 | // First WebSocket request, which has no credentials. |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 8742 | spdy::Http2HeaderBlock websocket_request_headers; |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8743 | websocket_request_headers[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 8744 | websocket_request_headers[spdy::kHttp2AuthorityHeader] = "server"; |
| 8745 | websocket_request_headers[spdy::kHttp2SchemeHeader] = "https"; |
| 8746 | websocket_request_headers[spdy::kHttp2PathHeader] = "/"; |
| 8747 | websocket_request_headers[spdy::kHttp2ProtocolHeader] = "websocket"; |
| 8748 | websocket_request_headers["origin"] = "http://server"; |
| 8749 | websocket_request_headers["sec-websocket-version"] = "13"; |
| 8750 | websocket_request_headers["sec-websocket-extensions"] = |
| 8751 | "permessage-deflate; client_max_window_bits"; |
| 8752 | spdy::SpdySerializedFrame websocket_request(spdy_util_.ConstructSpdyHeaders( |
| 8753 | 3, std::move(websocket_request_headers), MEDIUM, false)); |
| 8754 | |
| 8755 | // Auth challenge to WebSocket request. |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 8756 | spdy::Http2HeaderBlock auth_challenge_headers; |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 8757 | auth_challenge_headers[spdy::kHttp2StatusHeader] = "401"; |
| 8758 | auth_challenge_headers["www-authenticate"] = "NTLM"; |
| 8759 | spdy::SpdySerializedFrame websocket_auth_challenge( |
| 8760 | spdy_util_.ConstructSpdyResponseHeaders( |
| 8761 | 3, std::move(auth_challenge_headers), true)); |
| 8762 | |
| 8763 | MockWrite writes0[] = {CreateMockWrite(initial_request, 0), |
| 8764 | CreateMockWrite(settings_ack, 2), |
| 8765 | CreateMockWrite(websocket_request, 4), |
| 8766 | MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 7)}; |
| 8767 | MockRead reads0[] = {CreateMockRead(settings_frame, 1), |
| 8768 | CreateMockRead(initial_response, 3), |
| 8769 | CreateMockRead(websocket_auth_challenge, 5), |
| 8770 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6)}; |
| 8771 | |
| 8772 | // Generate the NTLM messages based on known test data. |
| 8773 | std::string negotiate_msg; |
| 8774 | std::string challenge_msg; |
| 8775 | std::string authenticate_msg; |
| 8776 | base::Base64Encode( |
| 8777 | base::StringPiece( |
| 8778 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 8779 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
| 8780 | &negotiate_msg); |
| 8781 | base::Base64Encode( |
| 8782 | base::StringPiece( |
| 8783 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 8784 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
| 8785 | &challenge_msg); |
| 8786 | base::Base64Encode( |
| 8787 | base::StringPiece( |
| 8788 | reinterpret_cast<const char*>( |
| 8789 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 8790 | base::size( |
| 8791 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 8792 | &authenticate_msg); |
| 8793 | |
| 8794 | // Retry yet again using HTTP/1.1. |
| 8795 | MockWrite writes1[] = { |
| 8796 | // After restarting with a null identity, this is the |
| 8797 | // request we should be issuing -- the final header line contains a Type |
| 8798 | // 1 message. |
| 8799 | MockWrite("GET / HTTP/1.1\r\n" |
| 8800 | "Host: server\r\n" |
| 8801 | "Connection: Upgrade\r\n" |
| 8802 | "Authorization: NTLM "), |
| 8803 | MockWrite(negotiate_msg.c_str()), |
| 8804 | MockWrite("\r\n"), |
| 8805 | MockWrite("Origin: http://server\r\n" |
| 8806 | "Sec-WebSocket-Version: 13\r\n" |
| 8807 | "Upgrade: websocket\r\n" |
| 8808 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 8809 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 8810 | "client_max_window_bits\r\n\r\n"), |
| 8811 | |
| 8812 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 8813 | // (the credentials for the origin server). The second request continues |
| 8814 | // on the same connection. |
| 8815 | MockWrite("GET / HTTP/1.1\r\n" |
| 8816 | "Host: server\r\n" |
| 8817 | "Connection: Upgrade\r\n" |
| 8818 | "Authorization: NTLM "), |
| 8819 | MockWrite(authenticate_msg.c_str()), |
| 8820 | MockWrite("\r\n"), |
| 8821 | MockWrite("Origin: http://server\r\n" |
| 8822 | "Sec-WebSocket-Version: 13\r\n" |
| 8823 | "Upgrade: websocket\r\n" |
| 8824 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 8825 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 8826 | "client_max_window_bits\r\n\r\n"), |
| 8827 | }; |
| 8828 | |
| 8829 | MockRead reads1[] = { |
| 8830 | // The origin server responds with a Type 2 message. |
| 8831 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 8832 | MockRead("WWW-Authenticate: NTLM "), |
| 8833 | MockRead(challenge_msg.c_str()), |
| 8834 | MockRead("\r\n"), |
| 8835 | MockRead("Content-Length: 42\r\n"), |
| 8836 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 8837 | MockRead("You are not authorized to view this page\r\n"), |
| 8838 | |
| 8839 | // Lastly we get the desired content. |
| 8840 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 8841 | "Upgrade: websocket\r\n" |
| 8842 | "Connection: Upgrade\r\n" |
| 8843 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 8844 | }; |
| 8845 | SequencedSocketData data0(reads0, writes0); |
| 8846 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 8847 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 8848 | ssl0.next_proto = kProtoHTTP2; |
| 8849 | ssl0.next_protos_expected_in_ssl_config = |
| 8850 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
| 8851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 8852 | |
| 8853 | StaticSocketDataProvider data1(reads1, writes1); |
| 8854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8855 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 8856 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 8857 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{}; |
| 8858 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 8859 | |
| 8860 | session_deps_.enable_websocket_over_http2 = true; |
| 8861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8862 | |
| 8863 | HttpRequestInfo initial_request_info; |
| 8864 | initial_request_info.method = "GET"; |
| 8865 | initial_request_info.url = kInitialUrl; |
| 8866 | initial_request_info.traffic_annotation = |
| 8867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8868 | HttpNetworkTransaction initial_trans(DEFAULT_PRIORITY, session.get()); |
| 8869 | TestCompletionCallback initial_callback; |
| 8870 | int rv = initial_trans.Start(&initial_request_info, |
| 8871 | initial_callback.callback(), NetLogWithSource()); |
| 8872 | EXPECT_THAT(initial_callback.GetResult(rv), IsOk()); |
| 8873 | |
| 8874 | EXPECT_FALSE(session->http_server_properties()->RequiresHTTP11( |
| 8875 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 8876 | |
| 8877 | HttpRequestInfo websocket_request_info; |
| 8878 | websocket_request_info.method = "GET"; |
| 8879 | websocket_request_info.url = kWebSocketUrl; |
| 8880 | websocket_request_info.traffic_annotation = |
| 8881 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8882 | EXPECT_TRUE(HostPortPair::FromURL(initial_request_info.url) |
| 8883 | .Equals(HostPortPair::FromURL(websocket_request_info.url))); |
| 8884 | websocket_request_info.extra_headers.SetHeader("Origin", "http://server"); |
| 8885 | websocket_request_info.extra_headers.SetHeader("Sec-WebSocket-Version", "13"); |
| 8886 | // The following two headers must be removed by WebSocketHttp2HandshakeStream. |
| 8887 | websocket_request_info.extra_headers.SetHeader("Connection", "Upgrade"); |
| 8888 | websocket_request_info.extra_headers.SetHeader("Upgrade", "websocket"); |
| 8889 | |
| 8890 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 8891 | |
| 8892 | HttpNetworkTransaction websocket_trans(MEDIUM, session.get()); |
| 8893 | websocket_trans.SetWebSocketHandshakeStreamCreateHelper( |
| 8894 | &websocket_stream_create_helper); |
| 8895 | |
| 8896 | TestCompletionCallback websocket_callback; |
| 8897 | rv = websocket_trans.Start(&websocket_request_info, |
| 8898 | websocket_callback.callback(), NetLogWithSource()); |
| 8899 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8900 | |
| 8901 | EXPECT_FALSE(websocket_trans.IsReadyToRestartForAuth()); |
| 8902 | |
| 8903 | const HttpResponseInfo* response = websocket_trans.GetResponseInfo(); |
| 8904 | ASSERT_TRUE(response); |
| 8905 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
| 8906 | |
| 8907 | rv = websocket_trans.RestartWithAuth( |
| 8908 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8909 | websocket_callback.callback()); |
| 8910 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8911 | |
| 8912 | EXPECT_TRUE(websocket_trans.IsReadyToRestartForAuth()); |
| 8913 | |
| 8914 | response = websocket_trans.GetResponseInfo(); |
| 8915 | ASSERT_TRUE(response); |
| 8916 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 8917 | |
| 8918 | rv = websocket_trans.RestartWithAuth(AuthCredentials(), |
| 8919 | websocket_callback.callback()); |
| 8920 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8921 | |
| 8922 | // The server should have been marked as requiring HTTP/1.1. The important |
| 8923 | // part here is that the scheme that requires HTTP/1.1 should be HTTPS, not |
| 8924 | // WSS. |
| 8925 | EXPECT_TRUE(session->http_server_properties()->RequiresHTTP11( |
| 8926 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 8927 | } |
| 8928 | |
| 8929 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 8930 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8931 | // 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] | 8932 | // do no retry forever as a result of TLS retries. This is a regression test for |
| 8933 | // https://crbug.com/823387. The version interference probe has since been |
| 8934 | // removed, but we now have a legacy crypto fallback. (If that fallback is |
| 8935 | // removed, this test should be kept but with the expectations tweaked, in case |
| 8936 | // future fallbacks are added.) |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8937 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 8938 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 8939 | // https://origin/. |
| 8940 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 8941 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8942 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8943 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 8944 | SSLContextConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8945 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 8946 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8947 | |
| 8948 | HttpRequestInfo request; |
| 8949 | request.method = "GET"; |
| 8950 | request.url = GURL("https://origin/"); |
| 8951 | request.traffic_annotation = |
| 8952 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8953 | |
| 8954 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 8955 | // to other auth schemes. |
| 8956 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 8957 | |
Asanka Herath | bf0b55d | 2019-12-07 03:27:09 | [diff] [blame] | 8958 | HttpAuthNtlmMechanism::ScopedProcSetter proc_setter( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8959 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 8960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8961 | |
| 8962 | // Generate the NTLM messages based on known test data. |
| 8963 | std::string negotiate_msg; |
| 8964 | std::string challenge_msg; |
| 8965 | std::string authenticate_msg; |
| 8966 | base::Base64Encode( |
| 8967 | base::StringPiece( |
| 8968 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8969 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8970 | &negotiate_msg); |
| 8971 | base::Base64Encode( |
| 8972 | base::StringPiece( |
| 8973 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8974 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8975 | &challenge_msg); |
| 8976 | base::Base64Encode( |
| 8977 | base::StringPiece( |
| 8978 | reinterpret_cast<const char*>( |
| 8979 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8980 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8981 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 8982 | &authenticate_msg); |
| 8983 | |
| 8984 | MockWrite data_writes[] = { |
| 8985 | // The initial CONNECT request. |
| 8986 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8987 | "Host: origin:443\r\n" |
| 8988 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8989 | |
| 8990 | // After restarting with an identity. |
| 8991 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8992 | "Host: origin:443\r\n" |
| 8993 | "Proxy-Connection: keep-alive\r\n" |
| 8994 | "Proxy-Authorization: NTLM "), |
| 8995 | MockWrite(negotiate_msg.c_str()), |
| 8996 | // End headers. |
| 8997 | MockWrite("\r\n\r\n"), |
| 8998 | |
| 8999 | // The second restart. |
| 9000 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 9001 | "Host: origin:443\r\n" |
| 9002 | "Proxy-Connection: keep-alive\r\n" |
| 9003 | "Proxy-Authorization: NTLM "), |
| 9004 | MockWrite(authenticate_msg.c_str()), |
| 9005 | // End headers. |
| 9006 | MockWrite("\r\n\r\n"), |
| 9007 | }; |
| 9008 | |
| 9009 | MockRead data_reads[] = { |
| 9010 | // The initial NTLM response. |
| 9011 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 9012 | "Content-Length: 0\r\n" |
| 9013 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 9014 | |
| 9015 | // The NTLM challenge message. |
| 9016 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 9017 | "Content-Length: 0\r\n" |
| 9018 | "Proxy-Authenticate: NTLM "), |
| 9019 | MockRead(challenge_msg.c_str()), |
| 9020 | // End headers. |
| 9021 | MockRead("\r\n\r\n"), |
| 9022 | |
| 9023 | // Finally the tunnel is established. |
| 9024 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 9025 | }; |
| 9026 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9027 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9028 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9031 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 9032 | StaticSocketDataProvider data2(data_reads, data_writes); |
| 9033 | SSLSocketDataProvider data2_ssl(ASYNC, ERR_CONNECTION_RESET); |
| 9034 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data2_ssl); |
| 9036 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9037 | // Start the transaction. The proxy responds with an NTLM authentication |
| 9038 | // request. |
| 9039 | TestCompletionCallback callback; |
| 9040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9041 | int rv = callback.GetResult( |
| 9042 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 9043 | |
| 9044 | EXPECT_THAT(rv, IsOk()); |
| 9045 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 9046 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 9047 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9048 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9049 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 9050 | // Configure credentials and restart. The proxy responds with the challenge |
| 9051 | // message. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9052 | rv = callback.GetResult(trans.RestartWithAuth( |
| 9053 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 9054 | callback.callback())); |
| 9055 | EXPECT_THAT(rv, IsOk()); |
| 9056 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 9057 | response = trans.GetResponseInfo(); |
| 9058 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9059 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9060 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 9061 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 9062 | // will reset. The fallback will then kick in and restart the process. The |
| 9063 | // proxy responds with another NTLM authentiation request, but we don't need |
| 9064 | // to provide credentials as the cached ones work. |
| 9065 | rv = callback.GetResult( |
| 9066 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 9067 | EXPECT_THAT(rv, IsOk()); |
| 9068 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 9069 | response = trans.GetResponseInfo(); |
| 9070 | ASSERT_TRUE(response); |
| 9071 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 9072 | |
| 9073 | // The proxy responds with the NTLM challenge message. |
| 9074 | rv = callback.GetResult( |
| 9075 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 9076 | EXPECT_THAT(rv, IsOk()); |
| 9077 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 9078 | response = trans.GetResponseInfo(); |
| 9079 | ASSERT_TRUE(response); |
| 9080 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 9081 | |
| 9082 | // Send the NTLM authenticate message. The tunnel is established and the |
| 9083 | // handshake resets again. We should not retry again. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 9084 | rv = callback.GetResult( |
| 9085 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 9086 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 9087 | } |
| 9088 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 9089 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 9090 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9091 | // Test reading a server response which has only headers, and no body. |
| 9092 | // After some maximum number of bytes is consumed, the transaction should |
| 9093 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9094 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9095 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9096 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9097 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9098 | request.traffic_annotation = |
| 9099 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9100 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9101 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9102 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9103 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 9104 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 9105 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 9106 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9107 | |
| 9108 | MockRead data_reads[] = { |
| 9109 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9110 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9111 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9112 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9113 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9114 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9115 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9117 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9118 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9119 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9121 | |
| 9122 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9123 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 9124 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9125 | |
| 9126 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 9127 | // establish tunnel. |
| 9128 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9129 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9130 | HttpRequestInfo request; |
| 9131 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9132 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9133 | request.traffic_annotation = |
| 9134 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9135 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9136 | // Configure against proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 9137 | session_deps_.proxy_resolution_service = |
| 9138 | ConfiguredProxyResolutionService::CreateFixed( |
| 9139 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 9140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9142 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9143 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9144 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9145 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9146 | // Since we have proxy, should try to establish tunnel. |
| 9147 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9148 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9149 | "Host: www.example.org:443\r\n" |
| 9150 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9151 | }; |
| 9152 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 9153 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9154 | // connection. Usually a proxy would return 501 (not implemented), |
| 9155 | // or 200 (tunnel established). |
| 9156 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 9157 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9158 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9159 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9160 | }; |
| 9161 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9162 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9163 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9165 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9166 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9167 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9168 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9169 | |
| 9170 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9171 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9172 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9173 | // Empty the current queue. This is necessary because idle sockets are |
| 9174 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9175 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9176 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9177 | // We now check to make sure the TCPClientSocket was not added back to |
| 9178 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9179 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9180 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9181 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9182 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9183 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 9184 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9185 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9186 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9187 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9188 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9189 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9190 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9191 | request.traffic_annotation = |
| 9192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9193 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9196 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9197 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9198 | MockRead data_reads[] = { |
| 9199 | // A part of the response body is received with the response headers. |
| 9200 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 9201 | // The rest of the response body is received in two parts. |
| 9202 | MockRead("lo"), |
| 9203 | MockRead(" world"), |
| 9204 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9206 | }; |
| 9207 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9208 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9209 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9211 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9213 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9215 | |
| 9216 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9219 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9220 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9221 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9222 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9223 | std::string status_line = response->headers->GetStatusLine(); |
| 9224 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 9225 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9226 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9227 | |
| 9228 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9229 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9231 | EXPECT_EQ("hello world", response_data); |
| 9232 | |
| 9233 | // Empty the current queue. This is necessary because idle sockets are |
| 9234 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9235 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9236 | |
| 9237 | // 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] | 9238 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 9239 | } |
| 9240 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9241 | // Make sure that we recycle a SSL socket after reading all of the response |
| 9242 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9243 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9244 | HttpRequestInfo request; |
| 9245 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9246 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9247 | request.traffic_annotation = |
| 9248 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9249 | |
| 9250 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9251 | MockWrite( |
| 9252 | "GET / HTTP/1.1\r\n" |
| 9253 | "Host: www.example.org\r\n" |
| 9254 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9255 | }; |
| 9256 | |
| 9257 | MockRead data_reads[] = { |
| 9258 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9259 | MockRead("Content-Length: 11\r\n\r\n"), |
| 9260 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9261 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9262 | }; |
| 9263 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9264 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9266 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9267 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9270 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9271 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9272 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9273 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9274 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9275 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9276 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9278 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9280 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9281 | ASSERT_TRUE(response); |
| 9282 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9283 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9284 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9285 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9286 | |
| 9287 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9288 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9289 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9290 | EXPECT_EQ("hello world", response_data); |
| 9291 | |
| 9292 | // Empty the current queue. This is necessary because idle sockets are |
| 9293 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9294 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9295 | |
| 9296 | // 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] | 9297 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9298 | } |
| 9299 | |
| 9300 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 9301 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9302 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9303 | HttpRequestInfo request; |
| 9304 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9305 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9306 | request.traffic_annotation = |
| 9307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9308 | |
| 9309 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9310 | MockWrite( |
| 9311 | "GET / HTTP/1.1\r\n" |
| 9312 | "Host: www.example.org\r\n" |
| 9313 | "Connection: keep-alive\r\n\r\n"), |
| 9314 | MockWrite( |
| 9315 | "GET / HTTP/1.1\r\n" |
| 9316 | "Host: www.example.org\r\n" |
| 9317 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9318 | }; |
| 9319 | |
| 9320 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 9321 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 9322 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9323 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9324 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 9325 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9326 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9328 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9329 | StaticSocketDataProvider data(data_reads, data_writes); |
| 9330 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9331 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9332 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9333 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9334 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9335 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9337 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9339 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9340 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9341 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9342 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9343 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9344 | |
| 9345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9346 | ASSERT_TRUE(response); |
| 9347 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9348 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9349 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9350 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9351 | |
| 9352 | std::string response_data; |
| 9353 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9354 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9355 | EXPECT_EQ("hello world", response_data); |
| 9356 | |
| 9357 | // Empty the current queue. This is necessary because idle sockets are |
| 9358 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9359 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9360 | |
| 9361 | // 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] | 9362 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9363 | |
| 9364 | // Now start the second transaction, which should reuse the previous socket. |
| 9365 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9366 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9367 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9369 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9370 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9372 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9373 | |
| 9374 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9375 | ASSERT_TRUE(response); |
| 9376 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9377 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9378 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9379 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9380 | |
| 9381 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9383 | EXPECT_EQ("hello world", response_data); |
| 9384 | |
| 9385 | // Empty the current queue. This is necessary because idle sockets are |
| 9386 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9387 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9388 | |
| 9389 | // 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] | 9390 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 9391 | } |
| 9392 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9393 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 9394 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9395 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9396 | HttpRequestInfo request; |
| 9397 | request.method = "GET"; |
| 9398 | request.url = GURL("http://www.example.org/"); |
| 9399 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9400 | request.traffic_annotation = |
| 9401 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9402 | |
| 9403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9406 | |
| 9407 | MockRead data_reads[] = { |
| 9408 | // A part of the response body is received with the response headers. |
| 9409 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 9410 | // The rest of the response body is received in two parts. |
| 9411 | MockRead("lo"), MockRead(" world"), |
| 9412 | MockRead("junk"), // Should not be read!! |
| 9413 | MockRead(SYNCHRONOUS, OK), |
| 9414 | }; |
| 9415 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9416 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9417 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9418 | |
| 9419 | TestCompletionCallback callback; |
| 9420 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9421 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9423 | |
| 9424 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 9425 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9426 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9427 | ASSERT_TRUE(response); |
| 9428 | EXPECT_TRUE(response->headers); |
| 9429 | std::string status_line = response->headers->GetStatusLine(); |
| 9430 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 9431 | |
| 9432 | // Make memory critical notification and ensure the transaction still has been |
| 9433 | // operating right. |
| 9434 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9435 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9436 | base::RunLoop().RunUntilIdle(); |
| 9437 | |
| 9438 | // Socket should not be flushed as long as it is not idle. |
| 9439 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9440 | |
| 9441 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9442 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsOk()); |
| 9444 | EXPECT_EQ("hello world", response_data); |
| 9445 | |
| 9446 | // Empty the current queue. This is necessary because idle sockets are |
| 9447 | // added to the connection pool asynchronously with a PostTask. |
| 9448 | base::RunLoop().RunUntilIdle(); |
| 9449 | |
| 9450 | // We now check to make sure the socket was added back to the pool. |
| 9451 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9452 | |
| 9453 | // Idle sockets should be flushed now. |
| 9454 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9455 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9456 | base::RunLoop().RunUntilIdle(); |
| 9457 | |
| 9458 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9459 | } |
| 9460 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 9461 | // Disable idle socket closing on memory pressure. |
| 9462 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 9463 | // low memory notification and ensure the socket pool is NOT flushed. |
| 9464 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 9465 | HttpRequestInfo request; |
| 9466 | request.method = "GET"; |
| 9467 | request.url = GURL("http://www.example.org/"); |
| 9468 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9469 | request.traffic_annotation = |
| 9470 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 9471 | |
| 9472 | // Disable idle socket closing on memory pressure. |
| 9473 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 9474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9475 | |
| 9476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9477 | |
| 9478 | MockRead data_reads[] = { |
| 9479 | // A part of the response body is received with the response headers. |
| 9480 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 9481 | // The rest of the response body is received in two parts. |
| 9482 | MockRead("lo"), MockRead(" world"), |
| 9483 | MockRead("junk"), // Should not be read!! |
| 9484 | MockRead(SYNCHRONOUS, OK), |
| 9485 | }; |
| 9486 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9487 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 9488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9489 | |
| 9490 | TestCompletionCallback callback; |
| 9491 | |
| 9492 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9494 | |
| 9495 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 9496 | |
| 9497 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 9498 | ASSERT_TRUE(response); |
| 9499 | EXPECT_TRUE(response->headers); |
| 9500 | std::string status_line = response->headers->GetStatusLine(); |
| 9501 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 9502 | |
| 9503 | // Make memory critical notification and ensure the transaction still has been |
| 9504 | // operating right. |
| 9505 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9506 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9507 | base::RunLoop().RunUntilIdle(); |
| 9508 | |
| 9509 | // Socket should not be flushed as long as it is not idle. |
| 9510 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9511 | |
| 9512 | std::string response_data; |
| 9513 | rv = ReadTransaction(&trans, &response_data); |
| 9514 | EXPECT_THAT(rv, IsOk()); |
| 9515 | EXPECT_EQ("hello world", response_data); |
| 9516 | |
| 9517 | // Empty the current queue. This is necessary because idle sockets are |
| 9518 | // added to the connection pool asynchronously with a PostTask. |
| 9519 | base::RunLoop().RunUntilIdle(); |
| 9520 | |
| 9521 | // We now check to make sure the socket was added back to the pool. |
| 9522 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9523 | |
| 9524 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 9525 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9526 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 9527 | base::RunLoop().RunUntilIdle(); |
| 9528 | |
| 9529 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9530 | |
| 9531 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 9532 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9533 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9534 | base::RunLoop().RunUntilIdle(); |
| 9535 | |
| 9536 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 9537 | } |
| 9538 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9539 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 9540 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9541 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9542 | HttpRequestInfo request; |
| 9543 | request.method = "GET"; |
| 9544 | request.url = GURL("https://www.example.org/"); |
| 9545 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9546 | request.traffic_annotation = |
| 9547 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9548 | |
| 9549 | MockWrite data_writes[] = { |
| 9550 | MockWrite("GET / HTTP/1.1\r\n" |
| 9551 | "Host: www.example.org\r\n" |
| 9552 | "Connection: keep-alive\r\n\r\n"), |
| 9553 | }; |
| 9554 | |
| 9555 | MockRead data_reads[] = { |
| 9556 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 9557 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 9558 | |
| 9559 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 9560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9561 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9562 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9563 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9564 | |
| 9565 | TestCompletionCallback callback; |
| 9566 | |
| 9567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9569 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 9570 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9571 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9572 | |
| 9573 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 9574 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9575 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9576 | ASSERT_TRUE(response); |
| 9577 | ASSERT_TRUE(response->headers); |
| 9578 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9579 | |
| 9580 | // Make memory critical notification and ensure the transaction still has been |
| 9581 | // operating right. |
| 9582 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9583 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9584 | base::RunLoop().RunUntilIdle(); |
| 9585 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 9586 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9587 | |
| 9588 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9589 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9590 | EXPECT_THAT(rv, IsOk()); |
| 9591 | EXPECT_EQ("hello world", response_data); |
| 9592 | |
| 9593 | // Empty the current queue. This is necessary because idle sockets are |
| 9594 | // added to the connection pool asynchronously with a PostTask. |
| 9595 | base::RunLoop().RunUntilIdle(); |
| 9596 | |
| 9597 | // 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] | 9598 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9599 | |
| 9600 | // Make memory notification once again and ensure idle socket is closed. |
| 9601 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 9602 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 9603 | base::RunLoop().RunUntilIdle(); |
| 9604 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 9605 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 9606 | } |
| 9607 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9608 | // Make sure that we recycle a socket after a zero-length response. |
| 9609 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9610 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9611 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9613 | request.url = GURL( |
| 9614 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 9615 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 9616 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 9617 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9618 | request.traffic_annotation = |
| 9619 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9620 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9621 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9622 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9623 | MockRead data_reads[] = { |
| 9624 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 9625 | "Content-Length: 0\r\n" |
| 9626 | "Content-Type: text/html\r\n\r\n"), |
| 9627 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9628 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9629 | }; |
| 9630 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9631 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9632 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9633 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 9634 | // Transaction must be created after the MockReads, so it's destroyed before |
| 9635 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9636 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 9637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9638 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9642 | |
| 9643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9646 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9647 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9648 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9649 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9650 | std::string status_line = response->headers->GetStatusLine(); |
| 9651 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 9652 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9653 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9654 | |
| 9655 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9656 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9657 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9658 | EXPECT_EQ("", response_data); |
| 9659 | |
| 9660 | // Empty the current queue. This is necessary because idle sockets are |
| 9661 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9662 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9663 | |
| 9664 | // 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] | 9665 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 9666 | } |
| 9667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9668 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9669 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9670 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9671 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9672 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9673 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9674 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9675 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 9676 | // after use. |
| 9677 | request[0].method = "GET"; |
| 9678 | request[0].url = GURL("http://www.google.com/"); |
| 9679 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9680 | request[0].traffic_annotation = |
| 9681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9682 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 9683 | // transaction 1. The first attempts fails when writing the POST data. |
| 9684 | // This causes the transaction to retry with a new socket. The second |
| 9685 | // attempt succeeds. |
| 9686 | request[1].method = "POST"; |
| 9687 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9688 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9689 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9690 | request[1].traffic_annotation = |
| 9691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9692 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9693 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9694 | |
| 9695 | // The first socket is used for transaction 1 and the first attempt of |
| 9696 | // transaction 2. |
| 9697 | |
| 9698 | // The response of transaction 1. |
| 9699 | MockRead data_reads1[] = { |
| 9700 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 9701 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9703 | }; |
| 9704 | // The mock write results of transaction 1 and the first attempt of |
| 9705 | // transaction 2. |
| 9706 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9707 | MockWrite(SYNCHRONOUS, 64), // GET |
| 9708 | MockWrite(SYNCHRONOUS, 93), // POST |
| 9709 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9710 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9711 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9712 | |
| 9713 | // The second socket is used for the second attempt of transaction 2. |
| 9714 | |
| 9715 | // The response of transaction 2. |
| 9716 | MockRead data_reads2[] = { |
| 9717 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 9718 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9719 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9720 | }; |
| 9721 | // The mock write results of the second attempt of transaction 2. |
| 9722 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9723 | MockWrite(SYNCHRONOUS, 93), // POST |
| 9724 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9725 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9726 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9727 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9728 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9729 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9730 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9731 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9732 | "hello world", "welcome" |
| 9733 | }; |
| 9734 | |
| 9735 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9738 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9739 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9740 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9742 | |
| 9743 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9744 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9746 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9747 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9748 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9749 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9750 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9751 | |
| 9752 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9753 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 9755 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 9756 | } |
| 9757 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9758 | |
| 9759 | // Test the request-challenge-retry sequence for basic auth when there is |
| 9760 | // 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] | 9761 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9762 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9763 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9765 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 9766 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9767 | request.traffic_annotation = |
| 9768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 9769 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9772 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 9773 | // The password contains an escaped character -- for this test to pass it |
| 9774 | // will need to be unescaped by HttpNetworkTransaction. |
| 9775 | EXPECT_EQ("b%40r", request.url.password()); |
| 9776 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9777 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9778 | MockWrite( |
| 9779 | "GET / HTTP/1.1\r\n" |
| 9780 | "Host: www.example.org\r\n" |
| 9781 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9782 | }; |
| 9783 | |
| 9784 | MockRead data_reads1[] = { |
| 9785 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9786 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9787 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9788 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9789 | }; |
| 9790 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9791 | // After the challenge above, the transaction will be restarted using the |
| 9792 | // identity from the url (foo, b@r) to answer the challenge. |
| 9793 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9794 | MockWrite( |
| 9795 | "GET / HTTP/1.1\r\n" |
| 9796 | "Host: www.example.org\r\n" |
| 9797 | "Connection: keep-alive\r\n" |
| 9798 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9799 | }; |
| 9800 | |
| 9801 | MockRead data_reads2[] = { |
| 9802 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9803 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9804 | MockRead(SYNCHRONOUS, OK), |
| 9805 | }; |
| 9806 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9807 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9808 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9810 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9812 | TestCompletionCallback callback1; |
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 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9816 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9817 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9818 | |
| 9819 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9820 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9822 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9823 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9824 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9826 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9827 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9828 | |
| 9829 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9830 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9831 | |
| 9832 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9833 | |
| 9834 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9835 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9836 | } |
| 9837 | |
| 9838 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 9839 | // incorrect identity in the URL. The identity from the URL should be used only |
| 9840 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9841 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9842 | HttpRequestInfo request; |
| 9843 | request.method = "GET"; |
| 9844 | // Note: the URL has a username:password in it. The password "baz" is |
| 9845 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9846 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9847 | |
| 9848 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9849 | request.traffic_annotation = |
| 9850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9851 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9853 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9854 | |
| 9855 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9856 | MockWrite( |
| 9857 | "GET / HTTP/1.1\r\n" |
| 9858 | "Host: www.example.org\r\n" |
| 9859 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9860 | }; |
| 9861 | |
| 9862 | MockRead data_reads1[] = { |
| 9863 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9864 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9865 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9866 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9867 | }; |
| 9868 | |
| 9869 | // After the challenge above, the transaction will be restarted using the |
| 9870 | // identity from the url (foo, baz) to answer the challenge. |
| 9871 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9872 | MockWrite( |
| 9873 | "GET / HTTP/1.1\r\n" |
| 9874 | "Host: www.example.org\r\n" |
| 9875 | "Connection: keep-alive\r\n" |
| 9876 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9877 | }; |
| 9878 | |
| 9879 | MockRead data_reads2[] = { |
| 9880 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9881 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9882 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9883 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9884 | }; |
| 9885 | |
| 9886 | // After the challenge above, the transaction will be restarted using the |
| 9887 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 9888 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9889 | MockWrite( |
| 9890 | "GET / HTTP/1.1\r\n" |
| 9891 | "Host: www.example.org\r\n" |
| 9892 | "Connection: keep-alive\r\n" |
| 9893 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9894 | }; |
| 9895 | |
| 9896 | MockRead data_reads3[] = { |
| 9897 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9898 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9899 | MockRead(SYNCHRONOUS, OK), |
| 9900 | }; |
| 9901 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9902 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9903 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9904 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9905 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9906 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9907 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9908 | |
| 9909 | TestCompletionCallback callback1; |
| 9910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9911 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9913 | |
| 9914 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9915 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9917 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9918 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9919 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9921 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9922 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9923 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9926 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9927 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9928 | |
| 9929 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9930 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9932 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9933 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9934 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9936 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9937 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9938 | |
| 9939 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9940 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 9941 | |
| 9942 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9943 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 9944 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9945 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 9946 | } |
| 9947 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9948 | |
| 9949 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 9950 | // correct identity in the URL, but its use is being suppressed. The identity |
| 9951 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9952 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9953 | HttpRequestInfo request; |
| 9954 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9955 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9956 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9957 | request.traffic_annotation = |
| 9958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9961 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9962 | |
| 9963 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9964 | MockWrite( |
| 9965 | "GET / HTTP/1.1\r\n" |
| 9966 | "Host: www.example.org\r\n" |
| 9967 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9968 | }; |
| 9969 | |
| 9970 | MockRead data_reads1[] = { |
| 9971 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9972 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9973 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9974 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9975 | }; |
| 9976 | |
| 9977 | // After the challenge above, the transaction will be restarted using the |
| 9978 | // identity supplied by the user, not the one in the URL, to answer the |
| 9979 | // challenge. |
| 9980 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9981 | MockWrite( |
| 9982 | "GET / HTTP/1.1\r\n" |
| 9983 | "Host: www.example.org\r\n" |
| 9984 | "Connection: keep-alive\r\n" |
| 9985 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9986 | }; |
| 9987 | |
| 9988 | MockRead data_reads3[] = { |
| 9989 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9990 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9991 | MockRead(SYNCHRONOUS, OK), |
| 9992 | }; |
| 9993 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9994 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9995 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9996 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9997 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9998 | |
| 9999 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10000 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10002 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10003 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10004 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10007 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10008 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10009 | |
| 10010 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10011 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10013 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10014 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10015 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10016 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10017 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10018 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10019 | |
| 10020 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10021 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10022 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10023 | |
| 10024 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10025 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 10026 | } |
| 10027 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10028 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10029 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10031 | |
| 10032 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 10033 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10034 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10036 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10037 | request.traffic_annotation = |
| 10038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10041 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10042 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10043 | MockWrite( |
| 10044 | "GET /x/y/z HTTP/1.1\r\n" |
| 10045 | "Host: www.example.org\r\n" |
| 10046 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10047 | }; |
| 10048 | |
| 10049 | MockRead data_reads1[] = { |
| 10050 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10051 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10052 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10053 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10054 | }; |
| 10055 | |
| 10056 | // Resend with authorization (username=foo, password=bar) |
| 10057 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10058 | MockWrite( |
| 10059 | "GET /x/y/z HTTP/1.1\r\n" |
| 10060 | "Host: www.example.org\r\n" |
| 10061 | "Connection: keep-alive\r\n" |
| 10062 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10063 | }; |
| 10064 | |
| 10065 | // Sever accepts the authorization. |
| 10066 | MockRead data_reads2[] = { |
| 10067 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10068 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10069 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10070 | }; |
| 10071 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10072 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10073 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10074 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10075 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10077 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10078 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10079 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10081 | |
| 10082 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10085 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10086 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10087 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10089 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10091 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10092 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10094 | |
| 10095 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10098 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10099 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10100 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10101 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10102 | } |
| 10103 | |
| 10104 | // ------------------------------------------------------------------------ |
| 10105 | |
| 10106 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 10107 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10108 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10109 | request.method = "GET"; |
| 10110 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 10111 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10112 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10113 | request.traffic_annotation = |
| 10114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10117 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10118 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10119 | MockWrite( |
| 10120 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 10121 | "Host: www.example.org\r\n" |
| 10122 | "Connection: keep-alive\r\n" |
| 10123 | // Send preemptive authorization for MyRealm1 |
| 10124 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10125 | }; |
| 10126 | |
| 10127 | // The server didn't like the preemptive authorization, and |
| 10128 | // challenges us for a different realm (MyRealm2). |
| 10129 | MockRead data_reads1[] = { |
| 10130 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10131 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 10132 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10133 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10134 | }; |
| 10135 | |
| 10136 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 10137 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10138 | MockWrite( |
| 10139 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 10140 | "Host: www.example.org\r\n" |
| 10141 | "Connection: keep-alive\r\n" |
| 10142 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10143 | }; |
| 10144 | |
| 10145 | // Sever accepts the authorization. |
| 10146 | MockRead data_reads2[] = { |
| 10147 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10148 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10149 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10150 | }; |
| 10151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10152 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10153 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10154 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10155 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10157 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10158 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10159 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10160 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10161 | |
| 10162 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10165 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10166 | ASSERT_TRUE(response); |
| 10167 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10168 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10169 | EXPECT_EQ("http://www.example.org", |
| 10170 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10171 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10172 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10174 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10176 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 10177 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10179 | |
| 10180 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10181 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10183 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10184 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10185 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10186 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10187 | } |
| 10188 | |
| 10189 | // ------------------------------------------------------------------------ |
| 10190 | |
| 10191 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 10192 | // succeed with preemptive authorization. |
| 10193 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10194 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10195 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10196 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10197 | request.traffic_annotation = |
| 10198 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10200 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10201 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10202 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10203 | MockWrite( |
| 10204 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 10205 | "Host: www.example.org\r\n" |
| 10206 | "Connection: keep-alive\r\n" |
| 10207 | // The authorization for MyRealm1 gets sent preemptively |
| 10208 | // (since the url is in the same protection space) |
| 10209 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10210 | }; |
| 10211 | |
| 10212 | // Sever accepts the preemptive authorization |
| 10213 | MockRead data_reads1[] = { |
| 10214 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10215 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10217 | }; |
| 10218 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10219 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10222 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10223 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10224 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10226 | |
| 10227 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10230 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10231 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10232 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10233 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10234 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10235 | } |
| 10236 | |
| 10237 | // ------------------------------------------------------------------------ |
| 10238 | |
| 10239 | // Transaction 4: request another URL in MyRealm (however the |
| 10240 | // url is not known to belong to the protection space, so no pre-auth). |
| 10241 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10242 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10243 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10244 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10245 | request.traffic_annotation = |
| 10246 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10248 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10249 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10250 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10251 | MockWrite( |
| 10252 | "GET /x/1 HTTP/1.1\r\n" |
| 10253 | "Host: www.example.org\r\n" |
| 10254 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10255 | }; |
| 10256 | |
| 10257 | MockRead data_reads1[] = { |
| 10258 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10259 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10260 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10261 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10262 | }; |
| 10263 | |
| 10264 | // Resend with authorization from MyRealm's cache. |
| 10265 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10266 | MockWrite( |
| 10267 | "GET /x/1 HTTP/1.1\r\n" |
| 10268 | "Host: www.example.org\r\n" |
| 10269 | "Connection: keep-alive\r\n" |
| 10270 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10271 | }; |
| 10272 | |
| 10273 | // Sever accepts the authorization. |
| 10274 | MockRead data_reads2[] = { |
| 10275 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10276 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10277 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10278 | }; |
| 10279 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10280 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10281 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10282 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10283 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10285 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10286 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10287 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10289 | |
| 10290 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10291 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10293 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10294 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10295 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10297 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10298 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10299 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10301 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10302 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10303 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10304 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10305 | } |
| 10306 | |
| 10307 | // ------------------------------------------------------------------------ |
| 10308 | |
| 10309 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 10310 | // cached identity. Should invalidate and re-prompt. |
| 10311 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10312 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10313 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10314 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10315 | request.traffic_annotation = |
| 10316 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10317 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10318 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10319 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10320 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10321 | MockWrite( |
| 10322 | "GET /p/q/t HTTP/1.1\r\n" |
| 10323 | "Host: www.example.org\r\n" |
| 10324 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10325 | }; |
| 10326 | |
| 10327 | MockRead data_reads1[] = { |
| 10328 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10329 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10330 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10331 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10332 | }; |
| 10333 | |
| 10334 | // Resend with authorization from cache for MyRealm. |
| 10335 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10336 | MockWrite( |
| 10337 | "GET /p/q/t HTTP/1.1\r\n" |
| 10338 | "Host: www.example.org\r\n" |
| 10339 | "Connection: keep-alive\r\n" |
| 10340 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10341 | }; |
| 10342 | |
| 10343 | // Sever rejects the authorization. |
| 10344 | MockRead data_reads2[] = { |
| 10345 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10346 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10347 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10348 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10349 | }; |
| 10350 | |
| 10351 | // At this point we should prompt for new credentials for MyRealm. |
| 10352 | // Restart with username=foo3, password=foo4. |
| 10353 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10354 | MockWrite( |
| 10355 | "GET /p/q/t HTTP/1.1\r\n" |
| 10356 | "Host: www.example.org\r\n" |
| 10357 | "Connection: keep-alive\r\n" |
| 10358 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10359 | }; |
| 10360 | |
| 10361 | // Sever accepts the authorization. |
| 10362 | MockRead data_reads3[] = { |
| 10363 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10364 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10365 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10366 | }; |
| 10367 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10368 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10369 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 10370 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10371 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10373 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10375 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10376 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10377 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10379 | |
| 10380 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10381 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10383 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10384 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10385 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10387 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10388 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10389 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10391 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10392 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10393 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10395 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10397 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 10398 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10400 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 10401 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10402 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10404 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10405 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10406 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 10407 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10408 | } |
| 10409 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10410 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10411 | // Tests that nonce count increments when multiple auth attempts |
| 10412 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10413 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 10414 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 10415 | new HttpAuthHandlerDigest::Factory(); |
| 10416 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 10417 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 10418 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10419 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10420 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10421 | |
| 10422 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 10423 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10424 | HttpRequestInfo request; |
| 10425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10426 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10427 | request.traffic_annotation = |
| 10428 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10429 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10430 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10431 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10432 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10433 | MockWrite( |
| 10434 | "GET /x/y/z HTTP/1.1\r\n" |
| 10435 | "Host: www.example.org\r\n" |
| 10436 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10437 | }; |
| 10438 | |
| 10439 | MockRead data_reads1[] = { |
| 10440 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 10441 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 10442 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10443 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10444 | }; |
| 10445 | |
| 10446 | // Resend with authorization (username=foo, password=bar) |
| 10447 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10448 | MockWrite( |
| 10449 | "GET /x/y/z HTTP/1.1\r\n" |
| 10450 | "Host: www.example.org\r\n" |
| 10451 | "Connection: keep-alive\r\n" |
| 10452 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 10453 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 10454 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 10455 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10456 | }; |
| 10457 | |
| 10458 | // Sever accepts the authorization. |
| 10459 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10460 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10462 | }; |
| 10463 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10464 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10465 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10466 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10467 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10469 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10471 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10473 | |
| 10474 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10478 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10479 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10481 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10483 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10484 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10486 | |
| 10487 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10490 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10491 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10492 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10493 | } |
| 10494 | |
| 10495 | // ------------------------------------------------------------------------ |
| 10496 | |
| 10497 | // Transaction 2: Request another resource in digestive's protection space. |
| 10498 | // This will preemptively add an Authorization header which should have an |
| 10499 | // "nc" value of 2 (as compared to 1 in the first use. |
| 10500 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10501 | HttpRequestInfo request; |
| 10502 | request.method = "GET"; |
| 10503 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 10504 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10505 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10506 | request.traffic_annotation = |
| 10507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10509 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10510 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10511 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10512 | MockWrite( |
| 10513 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 10514 | "Host: www.example.org\r\n" |
| 10515 | "Connection: keep-alive\r\n" |
| 10516 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 10517 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 10518 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 10519 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10520 | }; |
| 10521 | |
| 10522 | // Sever accepts the authorization. |
| 10523 | MockRead data_reads1[] = { |
| 10524 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10525 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10527 | }; |
| 10528 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10529 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10530 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10532 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10533 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10534 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10535 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10536 | |
| 10537 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10538 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10540 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10541 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10542 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 10543 | } |
| 10544 | } |
| 10545 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10546 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10547 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10548 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10549 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10550 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10551 | |
| 10552 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 10553 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10554 | trans.read_buf_len_ = 15; |
| 10555 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10556 | |
| 10557 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10558 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10559 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 10560 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10561 | response->response_time = base::Time::Now(); |
| 10562 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10563 | |
| 10564 | { // Setup state for response_.vary_data |
| 10565 | HttpRequestInfo request; |
| 10566 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 10567 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 10568 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10569 | request.extra_headers.SetHeader("Foo", "1"); |
| 10570 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10571 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10572 | } |
| 10573 | |
| 10574 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10575 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10576 | |
| 10577 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10578 | EXPECT_FALSE(trans.read_buf_); |
| 10579 | EXPECT_EQ(0, trans.read_buf_len_); |
| 10580 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10581 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10582 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 10583 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 10584 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10585 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 10586 | } |
| 10587 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10588 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10589 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10590 | HttpRequestInfo request; |
| 10591 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10592 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10593 | request.traffic_annotation = |
| 10594 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10595 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10596 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10597 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10598 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10599 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10600 | MockWrite( |
| 10601 | "GET / HTTP/1.1\r\n" |
| 10602 | "Host: www.example.org\r\n" |
| 10603 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10604 | }; |
| 10605 | |
| 10606 | MockRead data_reads[] = { |
| 10607 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10608 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10609 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10610 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10611 | }; |
| 10612 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 10613 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10614 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10615 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10616 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10617 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10618 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 10621 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10623 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10625 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10627 | |
| 10628 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10629 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10631 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10633 | |
| 10634 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10635 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10637 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10638 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10639 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10640 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10641 | } |
| 10642 | |
| 10643 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 10644 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10645 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10646 | session_deps_.proxy_resolution_service = |
| 10647 | ConfiguredProxyResolutionService::CreateFixed( |
| 10648 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10649 | |
| 10650 | HttpRequestInfo request; |
| 10651 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10652 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10653 | request.traffic_annotation = |
| 10654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10655 | |
| 10656 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10657 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10658 | "Host: www.example.org:443\r\n" |
| 10659 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10660 | }; |
| 10661 | |
| 10662 | MockRead proxy_reads[] = { |
| 10663 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10664 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10665 | }; |
| 10666 | |
| 10667 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10668 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10669 | "Host: www.example.org:443\r\n" |
| 10670 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10671 | MockWrite("GET / HTTP/1.1\r\n" |
| 10672 | "Host: www.example.org\r\n" |
| 10673 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10674 | }; |
| 10675 | |
| 10676 | MockRead data_reads[] = { |
| 10677 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10678 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10679 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10680 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10681 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10682 | }; |
| 10683 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10684 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 10685 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10686 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10687 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10688 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10689 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10690 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 10692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10694 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10695 | |
| 10696 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10697 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10701 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10702 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10704 | |
| 10705 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10706 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10708 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10710 | |
| 10711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10714 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10715 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10716 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 10717 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10718 | } |
| 10719 | } |
| 10720 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10721 | |
| 10722 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10723 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10724 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10725 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10726 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10727 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10728 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10729 | |
| 10730 | HttpRequestInfo request; |
| 10731 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10732 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10733 | request.traffic_annotation = |
| 10734 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10735 | |
| 10736 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10737 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10738 | "Host: www.example.org:443\r\n" |
| 10739 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10740 | MockWrite("GET / HTTP/1.1\r\n" |
| 10741 | "Host: www.example.org\r\n" |
| 10742 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10743 | }; |
| 10744 | |
| 10745 | MockRead data_reads[] = { |
| 10746 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10747 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10748 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10749 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10750 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10751 | }; |
| 10752 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10753 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10754 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 10755 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10756 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10757 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 10759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10761 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10765 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10766 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10768 | |
| 10769 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10770 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10771 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10772 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10773 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10774 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10775 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10776 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10777 | EXPECT_EQ(200, response->headers->response_code()); |
| 10778 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10779 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10780 | |
| 10781 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10782 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10783 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10784 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10785 | } |
| 10786 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 10787 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10788 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10789 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10790 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10791 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10792 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10793 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10794 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10795 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 10796 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 10797 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10798 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10799 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10801 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10802 | request.traffic_annotation = |
| 10803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10804 | |
| 10805 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10806 | MockWrite(ASYNC, 0, |
| 10807 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10808 | "Host: www.example.org:443\r\n" |
| 10809 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10810 | }; |
| 10811 | |
| 10812 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10813 | // Pause on first read. |
| 10814 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 10815 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 10816 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 10817 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10818 | }; |
| 10819 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10820 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10821 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10822 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10823 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10824 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10826 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10827 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10830 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10831 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10833 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 10834 | |
| 10835 | // Host resolution takes |kTimeIncrement|. |
| 10836 | FastForwardBy(kTimeIncrement); |
| 10837 | // Resolving the current request with |ResolveNow| will cause the pending |
| 10838 | // request to instantly complete, and the async connect will start as well. |
| 10839 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 10840 | |
| 10841 | // Connecting takes |kTimeIncrement|. |
| 10842 | FastForwardBy(kTimeIncrement); |
| 10843 | data.RunUntilPaused(); |
| 10844 | |
| 10845 | // The server takes |kTimeIncrement| to respond. |
| 10846 | FastForwardBy(kTimeIncrement); |
| 10847 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10848 | |
| 10849 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10850 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10851 | } |
| 10852 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10853 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 10854 | TEST_F(HttpNetworkTransactionTest, |
| 10855 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 10856 | base::HistogramTester histograms; |
| 10857 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10858 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10859 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10860 | RecordingTestNetLog net_log; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10861 | session_deps_.net_log = &net_log; |
| 10862 | |
| 10863 | HttpRequestInfo request; |
| 10864 | request.method = "GET"; |
| 10865 | request.url = GURL("https://www.example.org/"); |
| 10866 | request.traffic_annotation = |
| 10867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10868 | |
| 10869 | MockWrite data_writes[] = { |
| 10870 | MockWrite(ASYNC, 0, |
| 10871 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10872 | "Host: www.example.org:443\r\n" |
| 10873 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10874 | }; |
| 10875 | |
| 10876 | MockRead data_reads[] = { |
| 10877 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 10878 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 10879 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 10880 | }; |
| 10881 | |
| 10882 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 10883 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 10884 | |
| 10885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 10887 | |
| 10888 | TestCompletionCallback callback; |
| 10889 | |
| 10890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10891 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10892 | |
| 10893 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10895 | |
| 10896 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10897 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10898 | } |
| 10899 | |
| 10900 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 10901 | // request for main frames. |
| 10902 | TEST_F(HttpNetworkTransactionTest, |
| 10903 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 10904 | base::HistogramTester histograms; |
| 10905 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10906 | ConfiguredProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10907 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10908 | RecordingTestNetLog net_log; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10909 | session_deps_.net_log = &net_log; |
| 10910 | |
| 10911 | HttpRequestInfo request; |
| 10912 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 10913 | request.method = "GET"; |
| 10914 | request.url = GURL("https://www.example.org/"); |
| 10915 | request.traffic_annotation = |
| 10916 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10917 | |
| 10918 | MockWrite data_writes[] = { |
| 10919 | MockWrite(ASYNC, 0, |
| 10920 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10921 | "Host: www.example.org:443\r\n" |
| 10922 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10923 | }; |
| 10924 | |
| 10925 | MockRead data_reads[] = { |
| 10926 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 10927 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 10928 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 10929 | }; |
| 10930 | |
| 10931 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 10932 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 10933 | |
| 10934 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 10936 | |
| 10937 | TestCompletionCallback callback; |
| 10938 | |
| 10939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10941 | |
| 10942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10944 | |
| 10945 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10946 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10947 | } |
| 10948 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 10949 | // 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] | 10950 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10951 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10952 | base::HistogramTester histograms; |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 10953 | session_deps_.proxy_resolution_service = |
| 10954 | ConfiguredProxyResolutionService::CreateFixed( |
| 10955 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 10956 | RecordingTestNetLog net_log; |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10957 | session_deps_.net_log = &net_log; |
| 10958 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10959 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 10960 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10961 | |
| 10962 | HttpRequestInfo request; |
| 10963 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10964 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10965 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10966 | request.traffic_annotation = |
| 10967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10968 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10969 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10970 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10971 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10972 | spdy::SpdySerializedFrame goaway( |
| 10973 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10974 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10975 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10976 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10977 | }; |
| 10978 | |
| 10979 | static const char* const kExtraHeaders[] = { |
| 10980 | "location", |
| 10981 | "http://login.example.com/", |
| 10982 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10983 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10984 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10985 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10986 | // Pause on first read. |
| 10987 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 10988 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10989 | }; |
| 10990 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10991 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10992 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10993 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10994 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10998 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10999 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 11005 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11006 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 11007 | // Host resolution takes |kTimeIncrement|. |
| 11008 | FastForwardBy(kTimeIncrement); |
| 11009 | // Resolving the current request with |ResolveNow| will cause the pending |
| 11010 | // request to instantly complete, and the async connect will start as well. |
| 11011 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 11012 | |
| 11013 | // Connecting takes |kTimeIncrement|. |
| 11014 | FastForwardBy(kTimeIncrement); |
| 11015 | data.RunUntilPaused(); |
| 11016 | |
| 11017 | FastForwardBy(kTimeIncrement); |
| 11018 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11019 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 11020 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11021 | } |
| 11022 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 11023 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11024 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11025 | session_deps_.proxy_resolution_service = |
| 11026 | ConfiguredProxyResolutionService::CreateFixed( |
| 11027 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11028 | |
| 11029 | HttpRequestInfo request; |
| 11030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11031 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11032 | request.traffic_annotation = |
| 11033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11034 | |
| 11035 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11036 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11037 | "Host: www.example.org:443\r\n" |
| 11038 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11039 | }; |
| 11040 | |
| 11041 | MockRead data_reads[] = { |
| 11042 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 11043 | MockRead("Content-Length: 23\r\n\r\n"), |
| 11044 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11045 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11046 | }; |
| 11047 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11048 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11049 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11050 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11051 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11054 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11055 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11056 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11057 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11058 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11059 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11061 | |
| 11062 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11063 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11064 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 11065 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11066 | } |
| 11067 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 11068 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11069 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11070 | session_deps_.proxy_resolution_service = |
| 11071 | ConfiguredProxyResolutionService::CreateFixed( |
| 11072 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11073 | |
| 11074 | HttpRequestInfo request; |
| 11075 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11076 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11077 | request.traffic_annotation = |
| 11078 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11079 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11080 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 11081 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 11082 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11083 | spdy::SpdySerializedFrame rst( |
| 11084 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11085 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11086 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11087 | }; |
| 11088 | |
| 11089 | static const char* const kExtraHeaders[] = { |
| 11090 | "location", |
| 11091 | "http://login.example.com/", |
| 11092 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11093 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11094 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11095 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 11096 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11097 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11098 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11099 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11100 | }; |
| 11101 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11102 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11103 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11104 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11105 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11107 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11108 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11109 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11110 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11111 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11112 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11113 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11114 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11116 | |
| 11117 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11118 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11119 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 11120 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 11121 | } |
| 11122 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11123 | // Test the request-challenge-retry sequence for basic auth, through |
| 11124 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11125 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11126 | HttpRequestInfo request; |
| 11127 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11128 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11129 | // when the no authentication data flag is set. |
Matt Menke | 25eaa43 | 2020-08-25 00:10:00 | [diff] [blame] | 11130 | request.privacy_mode = PRIVACY_MODE_ENABLED; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11131 | request.traffic_annotation = |
| 11132 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11133 | |
| 11134 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11135 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11136 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11137 | "HTTPS myproxy:70", 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(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11140 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11141 | |
| 11142 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11143 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 11144 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 11145 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11146 | spdy::SpdySerializedFrame rst( |
| 11147 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11148 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11150 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11151 | // be issuing -- the final header line contains the credentials. |
| 11152 | const char* const kAuthCredentials[] = { |
| 11153 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 11154 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11155 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 11156 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 11157 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11158 | HostPortPair("www.example.org", 443))); |
| 11159 | // fetch https://www.example.org/ via HTTP |
| 11160 | const char get[] = |
| 11161 | "GET / HTTP/1.1\r\n" |
| 11162 | "Host: www.example.org\r\n" |
| 11163 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11164 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 11165 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11166 | |
| 11167 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11168 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 11169 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11170 | }; |
| 11171 | |
| 11172 | // The proxy responds to the connect with a 407, using a persistent |
| 11173 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11174 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11175 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11176 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 11177 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11178 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11179 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11180 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11181 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11182 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11183 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 11184 | "Content-Length: 5\r\n\r\n"; |
| 11185 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11186 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 11187 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11188 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 11189 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11190 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11191 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 11192 | CreateMockRead(conn_resp, 4, ASYNC), |
| 11193 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 11194 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11195 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11196 | }; |
| 11197 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11198 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11199 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11200 | // Negotiate SPDY to the proxy |
| 11201 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11202 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11204 | // Vanilla SSL to the server |
| 11205 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11207 | |
| 11208 | TestCompletionCallback callback1; |
| 11209 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11210 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11211 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11212 | |
| 11213 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11215 | |
| 11216 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11217 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 11218 | auto entries = log.GetEntries(); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11219 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 11220 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 11221 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11222 | ExpectLogContainsSomewhere( |
| 11223 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 11224 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11225 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11226 | |
| 11227 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11228 | ASSERT_TRUE(response); |
| 11229 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11230 | EXPECT_EQ(407, response->headers->response_code()); |
| 11231 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11232 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 11233 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11234 | |
| 11235 | TestCompletionCallback callback2; |
| 11236 | |
| 11237 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 11238 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11240 | |
| 11241 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11243 | |
| 11244 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11245 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11246 | |
| 11247 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11248 | EXPECT_EQ(200, response->headers->response_code()); |
| 11249 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 11250 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11251 | |
| 11252 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11253 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11254 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11255 | LoadTimingInfo load_timing_info; |
| 11256 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11257 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11258 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11259 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11260 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11261 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 11262 | } |
| 11263 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11264 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 11265 | // origin that is different from that of its associated resource. |
Matt Menke | df93ff7 | 2020-07-16 02:23:03 | [diff] [blame] | 11266 | TEST_F(HttpNetworkTransactionTest, CrossOriginSpdyProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11267 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11268 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11269 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 11270 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11271 | HttpRequestInfo request; |
| 11272 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11273 | request.traffic_annotation = |
| 11274 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11275 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11276 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11277 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11278 | push_request.method = "GET"; |
| 11279 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11280 | push_request.traffic_annotation = |
| 11281 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11282 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11283 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11284 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11285 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11286 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11287 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11288 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11289 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 11290 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 11291 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11292 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11294 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11295 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11296 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11297 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11298 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11299 | |
| 11300 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11301 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11302 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11303 | }; |
| 11304 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11305 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11306 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 11307 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11308 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11309 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11310 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11311 | spdy::SpdySerializedFrame stream1_body( |
| 11312 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11313 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11314 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 11315 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11316 | |
| 11317 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 11318 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 11319 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11320 | CreateMockRead(stream1_body, 4, ASYNC), |
| 11321 | CreateMockRead(stream2_body, 5, ASYNC), |
| 11322 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11323 | }; |
| 11324 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11325 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11326 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11327 | // Negotiate SPDY to the proxy |
| 11328 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11329 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11331 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11332 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11333 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11334 | TestCompletionCallback callback; |
| 11335 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11336 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11337 | |
| 11338 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11339 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11340 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11341 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11342 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11343 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11344 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11345 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11346 | |
| 11347 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11348 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11349 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 11350 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11351 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11352 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11353 | |
| 11354 | EXPECT_EQ(200, response->headers->response_code()); |
| 11355 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11356 | |
| 11357 | std::string response_data; |
| 11358 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11359 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11360 | EXPECT_EQ("hello!", response_data); |
| 11361 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11362 | LoadTimingInfo load_timing_info; |
| 11363 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11364 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11365 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11366 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11367 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11368 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11369 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 11370 | |
| 11371 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11373 | EXPECT_EQ("pushed", response_data); |
| 11374 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11375 | LoadTimingInfo push_load_timing_info; |
| 11376 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 11377 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 11378 | // The transactions should share a socket ID, despite being for different |
| 11379 | // origins. |
| 11380 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 11381 | push_load_timing_info.socket_log_id); |
| 11382 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11383 | trans.reset(); |
| 11384 | push_trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11385 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 11386 | } |
| 11387 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11388 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11389 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11390 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11391 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11392 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 11393 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11394 | HttpRequestInfo request; |
| 11395 | |
| 11396 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11397 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11398 | request.traffic_annotation = |
| 11399 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11400 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11401 | session_deps_.proxy_resolution_service = |
| 11402 | ConfiguredProxyResolutionService::CreateFixed( |
| 11403 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11404 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11405 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11406 | |
| 11407 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 11408 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 11409 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 11410 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11412 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11413 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11414 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11415 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11416 | spdy::SpdySerializedFrame push_rst( |
| 11417 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11418 | |
| 11419 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11420 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11421 | }; |
| 11422 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11423 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11424 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11425 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11426 | spdy::SpdySerializedFrame stream1_body( |
| 11427 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11428 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11429 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 11430 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11431 | |
| 11432 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11433 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 11434 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 11435 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 11436 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11437 | }; |
| 11438 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11439 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11440 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11441 | // Negotiate SPDY to the proxy |
| 11442 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11443 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11444 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11445 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11446 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11447 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11448 | TestCompletionCallback callback; |
| 11449 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11451 | |
| 11452 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11453 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11454 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11455 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11456 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11457 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11458 | |
| 11459 | EXPECT_EQ(200, response->headers->response_code()); |
| 11460 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11461 | |
| 11462 | std::string response_data; |
| 11463 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11464 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11465 | EXPECT_EQ("hello!", response_data); |
| 11466 | |
| 11467 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11468 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 11469 | } |
| 11470 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11471 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 11472 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11473 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11474 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11475 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 11476 | proxy_delegate->set_trusted_spdy_proxy( |
| 11477 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 11478 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11479 | HttpRequestInfo request; |
| 11480 | |
| 11481 | request.method = "GET"; |
| 11482 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11483 | request.traffic_annotation = |
| 11484 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11485 | |
| 11486 | // Configure against https proxy server "myproxy:70". |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11487 | session_deps_.proxy_resolution_service = |
| 11488 | ConfiguredProxyResolutionService::CreateFixed( |
| 11489 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 11490 | RecordingBoundTestNetLog log; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11491 | session_deps_.net_log = log.bound().net_log(); |
| 11492 | |
| 11493 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 11494 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 11495 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11498 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11499 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11500 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11501 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11502 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11503 | |
| 11504 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11505 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11506 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11507 | }; |
| 11508 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11509 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11510 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11511 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11512 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 11513 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11514 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11515 | spdy::SpdySerializedFrame stream1_body( |
| 11516 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11517 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11518 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11519 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11520 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11521 | spdy::SpdySerializedFrame stream2_body( |
| 11522 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11523 | |
| 11524 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11525 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 11526 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 11527 | CreateMockRead(stream1_body, 4, ASYNC), |
| 11528 | CreateMockRead(stream2_body, 5, ASYNC), |
| 11529 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11530 | }; |
| 11531 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11532 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11533 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11534 | // Negotiate SPDY to the proxy |
| 11535 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11536 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11537 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 11538 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11539 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11540 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11541 | TestCompletionCallback callback; |
| 11542 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11544 | |
| 11545 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11546 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11547 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11548 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11549 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11550 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11551 | |
| 11552 | EXPECT_EQ(200, response->headers->response_code()); |
| 11553 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11554 | |
| 11555 | std::string response_data; |
| 11556 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11557 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11558 | EXPECT_EQ("hello!", response_data); |
| 11559 | |
| 11560 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 11561 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 11562 | } |
| 11563 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11564 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 11565 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11566 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11567 | session_deps_.proxy_resolution_service = |
| 11568 | ConfiguredProxyResolutionService::CreateFixed( |
| 11569 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11570 | |
| 11571 | HttpRequestInfo request; |
| 11572 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11573 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11574 | request.traffic_annotation = |
| 11575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11576 | |
| 11577 | // Attempt to fetch the URL from a server with a bad cert |
| 11578 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11579 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11580 | "Host: www.example.org:443\r\n" |
| 11581 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11582 | }; |
| 11583 | |
| 11584 | MockRead bad_cert_reads[] = { |
| 11585 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11586 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11587 | }; |
| 11588 | |
| 11589 | // Attempt to fetch the URL with a good cert |
| 11590 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11591 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11592 | "Host: www.example.org:443\r\n" |
| 11593 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11594 | MockWrite("GET / HTTP/1.1\r\n" |
| 11595 | "Host: www.example.org\r\n" |
| 11596 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11597 | }; |
| 11598 | |
| 11599 | MockRead good_cert_reads[] = { |
| 11600 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 11601 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11602 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11603 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11604 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11605 | }; |
| 11606 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11607 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 11608 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11609 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 11610 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11611 | |
| 11612 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11614 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 11615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11616 | |
| 11617 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11622 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11623 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11626 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11627 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11629 | |
| 11630 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11631 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11633 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11635 | |
| 11636 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11637 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11639 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11640 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11641 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 11642 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11643 | } |
| 11644 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11645 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11646 | HttpRequestInfo request; |
| 11647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11648 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11649 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 11650 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11651 | request.traffic_annotation = |
| 11652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11656 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11657 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11658 | MockWrite( |
| 11659 | "GET / HTTP/1.1\r\n" |
| 11660 | "Host: www.example.org\r\n" |
| 11661 | "Connection: keep-alive\r\n" |
| 11662 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11663 | }; |
| 11664 | |
| 11665 | // Lastly, the server responds with the actual content. |
| 11666 | MockRead data_reads[] = { |
| 11667 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11668 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11669 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11670 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11671 | }; |
| 11672 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11673 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11674 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11675 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11676 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11677 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11678 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11680 | |
| 11681 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11682 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11683 | } |
| 11684 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11685 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11686 | // Test user agent values, used both for the request header of the original |
| 11687 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 11688 | // no request header / no HttpUserAgentSettings object. |
| 11689 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11690 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11691 | for (const char* setting_user_agent : kTestUserAgents) { |
| 11692 | if (!setting_user_agent) { |
| 11693 | session_deps_.http_user_agent_settings.reset(); |
| 11694 | } else { |
| 11695 | session_deps_.http_user_agent_settings = |
| 11696 | std::make_unique<StaticHttpUserAgentSettings>( |
| 11697 | std::string() /* accept-language */, setting_user_agent); |
| 11698 | } |
| 11699 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 11700 | ConfiguredProxyResolutionService::CreateFixed( |
| 11701 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11702 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11703 | for (const char* request_user_agent : kTestUserAgents) { |
| 11704 | HttpRequestInfo request; |
| 11705 | request.method = "GET"; |
| 11706 | request.url = GURL("https://www.example.org/"); |
| 11707 | if (request_user_agent) { |
| 11708 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 11709 | request_user_agent); |
| 11710 | } |
| 11711 | request.traffic_annotation = |
| 11712 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11713 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11715 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11716 | std::string expected_request; |
| 11717 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 11718 | expected_request = |
| 11719 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11720 | "Host: www.example.org:443\r\n" |
| 11721 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 11722 | } else { |
| 11723 | expected_request = base::StringPrintf( |
| 11724 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11725 | "Host: www.example.org:443\r\n" |
| 11726 | "Proxy-Connection: keep-alive\r\n" |
| 11727 | "User-Agent: %s\r\n\r\n", |
| 11728 | setting_user_agent); |
| 11729 | } |
| 11730 | MockWrite data_writes[] = { |
| 11731 | MockWrite(expected_request.c_str()), |
| 11732 | }; |
| 11733 | MockRead data_reads[] = { |
| 11734 | // Return an error, so the transaction stops here (this test isn't |
| 11735 | // interested in the rest). |
| 11736 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 11737 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11738 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 11739 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11740 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11741 | StaticSocketDataProvider data(data_reads, data_writes); |
| 11742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11743 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11744 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11745 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 11746 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11748 | |
| 11749 | rv = callback.WaitForResult(); |
| 11750 | EXPECT_THAT(rv, IsOk()); |
| 11751 | } |
| 11752 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 11753 | } |
| 11754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11755 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11756 | HttpRequestInfo request; |
| 11757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11758 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 11759 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 11760 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11761 | request.traffic_annotation = |
| 11762 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11766 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11767 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11768 | MockWrite( |
| 11769 | "GET / HTTP/1.1\r\n" |
| 11770 | "Host: www.example.org\r\n" |
| 11771 | "Connection: keep-alive\r\n" |
| 11772 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11773 | }; |
| 11774 | |
| 11775 | // Lastly, the server responds with the actual content. |
| 11776 | MockRead data_reads[] = { |
| 11777 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11778 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11779 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11780 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11781 | }; |
| 11782 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11783 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11786 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11787 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11788 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11790 | |
| 11791 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11792 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11793 | } |
| 11794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11795 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11796 | HttpRequestInfo request; |
| 11797 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11798 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11799 | request.traffic_annotation = |
| 11800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11801 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11803 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11804 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11805 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11806 | MockWrite( |
| 11807 | "POST / HTTP/1.1\r\n" |
| 11808 | "Host: www.example.org\r\n" |
| 11809 | "Connection: keep-alive\r\n" |
| 11810 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11811 | }; |
| 11812 | |
| 11813 | // Lastly, the server responds with the actual content. |
| 11814 | MockRead data_reads[] = { |
| 11815 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11816 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11817 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11819 | }; |
| 11820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11821 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11822 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11824 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11825 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11826 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11828 | |
| 11829 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11831 | } |
| 11832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11833 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11834 | HttpRequestInfo request; |
| 11835 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11836 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11837 | request.traffic_annotation = |
| 11838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11839 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11840 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11841 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11842 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11843 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11844 | MockWrite( |
| 11845 | "PUT / HTTP/1.1\r\n" |
| 11846 | "Host: www.example.org\r\n" |
| 11847 | "Connection: keep-alive\r\n" |
| 11848 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11849 | }; |
| 11850 | |
| 11851 | // Lastly, the server responds with the actual content. |
| 11852 | MockRead data_reads[] = { |
| 11853 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11854 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11855 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11856 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11857 | }; |
| 11858 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11859 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11860 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11862 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11864 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11866 | |
| 11867 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11868 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11869 | } |
| 11870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11871 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11872 | HttpRequestInfo request; |
| 11873 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11874 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11875 | request.traffic_annotation = |
| 11876 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11877 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11878 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11879 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11880 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11881 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 11882 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 11883 | "Host: www.example.org\r\n" |
| 11884 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11885 | }; |
| 11886 | |
| 11887 | // Lastly, the server responds with the actual content. |
| 11888 | MockRead data_reads[] = { |
| 11889 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11890 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11891 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11892 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11893 | }; |
| 11894 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11895 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11896 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11898 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11902 | |
| 11903 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11904 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11905 | } |
| 11906 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11907 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11908 | HttpRequestInfo request; |
| 11909 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11910 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11911 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11912 | request.traffic_annotation = |
| 11913 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11914 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11917 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11918 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11919 | MockWrite( |
| 11920 | "GET / HTTP/1.1\r\n" |
| 11921 | "Host: www.example.org\r\n" |
| 11922 | "Connection: keep-alive\r\n" |
| 11923 | "Pragma: no-cache\r\n" |
| 11924 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11925 | }; |
| 11926 | |
| 11927 | // Lastly, the server responds with the actual content. |
| 11928 | MockRead data_reads[] = { |
| 11929 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11930 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11931 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11932 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11933 | }; |
| 11934 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11935 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11938 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11942 | |
| 11943 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11944 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11945 | } |
| 11946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11947 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11948 | HttpRequestInfo request; |
| 11949 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11950 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11951 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11952 | request.traffic_annotation = |
| 11953 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11954 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11957 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11958 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11959 | MockWrite( |
| 11960 | "GET / HTTP/1.1\r\n" |
| 11961 | "Host: www.example.org\r\n" |
| 11962 | "Connection: keep-alive\r\n" |
| 11963 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11964 | }; |
| 11965 | |
| 11966 | // Lastly, the server responds with the actual content. |
| 11967 | MockRead data_reads[] = { |
| 11968 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11969 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11970 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11971 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11972 | }; |
| 11973 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11974 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11975 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11977 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11978 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11979 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11981 | |
| 11982 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11983 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11984 | } |
| 11985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11986 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11987 | HttpRequestInfo request; |
| 11988 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11989 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11990 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11991 | request.traffic_annotation = |
| 11992 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11995 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11996 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11997 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11998 | MockWrite( |
| 11999 | "GET / HTTP/1.1\r\n" |
| 12000 | "Host: www.example.org\r\n" |
| 12001 | "Connection: keep-alive\r\n" |
| 12002 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 12003 | }; |
| 12004 | |
| 12005 | // Lastly, the server responds with the actual content. |
| 12006 | MockRead data_reads[] = { |
| 12007 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12008 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12009 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12010 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 12011 | }; |
| 12012 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12013 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12014 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 12015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12016 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 12017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12018 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 12020 | |
| 12021 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12022 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 12023 | } |
| 12024 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12025 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12026 | HttpRequestInfo request; |
| 12027 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12028 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 12029 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 12030 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 12031 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12032 | request.traffic_annotation = |
| 12033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12037 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12038 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12039 | MockWrite( |
| 12040 | "GET / HTTP/1.1\r\n" |
| 12041 | "Host: www.example.org\r\n" |
| 12042 | "Connection: keep-alive\r\n" |
| 12043 | "referer: www.foo.com\r\n" |
| 12044 | "hEllo: Kitty\r\n" |
| 12045 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12046 | }; |
| 12047 | |
| 12048 | // Lastly, the server responds with the actual content. |
| 12049 | MockRead data_reads[] = { |
| 12050 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12051 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12052 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12053 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12054 | }; |
| 12055 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12056 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12059 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12061 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12063 | |
| 12064 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12065 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 12066 | } |
| 12067 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12068 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12069 | HttpRequestInfo request; |
| 12070 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12071 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12072 | request.traffic_annotation = |
| 12073 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12074 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12075 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12076 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12077 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 12078 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12079 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12080 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12082 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12083 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12084 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 12085 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 12086 | |
| 12087 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12088 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 12089 | MockWrite("GET / HTTP/1.1\r\n" |
| 12090 | "Host: www.example.org\r\n" |
| 12091 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12092 | |
| 12093 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12094 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 12095 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12096 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12097 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12098 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12099 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12102 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12103 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12104 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12106 | |
| 12107 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12110 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12111 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12112 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12113 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12114 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12115 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12116 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12117 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 12118 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12119 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12120 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12122 | EXPECT_EQ("Payload", response_text); |
| 12123 | } |
| 12124 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12125 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12126 | HttpRequestInfo request; |
| 12127 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12128 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12129 | request.traffic_annotation = |
| 12130 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12131 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12132 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12133 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12134 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 12135 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12136 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12137 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12138 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12140 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12141 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 12142 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 12143 | |
| 12144 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12145 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12146 | base::size(write_buffer)), |
| 12147 | MockWrite("GET / HTTP/1.1\r\n" |
| 12148 | "Host: www.example.org\r\n" |
| 12149 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12150 | |
| 12151 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12152 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 12153 | base::size(read_buffer)), |
| 12154 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12155 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12156 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12157 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12158 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12160 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12161 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12164 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12165 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12166 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12167 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12168 | |
| 12169 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12170 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12171 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12172 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12173 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12174 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12175 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12177 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12178 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12179 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12180 | |
| 12181 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12182 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12183 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12184 | EXPECT_EQ("Payload", response_text); |
| 12185 | } |
| 12186 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12187 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12188 | HttpRequestInfo request; |
| 12189 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12190 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12191 | request.traffic_annotation = |
| 12192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12193 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12194 | session_deps_.proxy_resolution_service = |
| 12195 | ConfiguredProxyResolutionService::CreateFixed( |
| 12196 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 12197 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12198 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12199 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12202 | |
| 12203 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 12204 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 12205 | |
| 12206 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12207 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 12208 | MockWrite("GET / HTTP/1.1\r\n" |
| 12209 | "Host: www.example.org\r\n" |
| 12210 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12211 | |
| 12212 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12213 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 12214 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12215 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12216 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12218 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12219 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12220 | |
| 12221 | TestCompletionCallback callback; |
| 12222 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12223 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12224 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12225 | |
| 12226 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12227 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12229 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12230 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12231 | |
| 12232 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12233 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12234 | TestLoadTimingNotReused(load_timing_info, |
| 12235 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 12236 | |
| 12237 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12238 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12239 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12240 | EXPECT_EQ("Payload", response_text); |
| 12241 | } |
| 12242 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12243 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12244 | HttpRequestInfo request; |
| 12245 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12246 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12247 | request.traffic_annotation = |
| 12248 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12249 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12250 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12251 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12252 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 12253 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12254 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12255 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12256 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12257 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12258 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12259 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 12260 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12261 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12262 | 0x05, // Version |
| 12263 | 0x01, // Command (CONNECT) |
| 12264 | 0x00, // Reserved. |
| 12265 | 0x03, // Address type (DOMAINNAME). |
| 12266 | 0x0F, // Length of domain (15) |
| 12267 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 12268 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12269 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12270 | const char kSOCKS5OkResponse[] = |
| 12271 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 12272 | |
| 12273 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12274 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 12275 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 12276 | MockWrite("GET / HTTP/1.1\r\n" |
| 12277 | "Host: www.example.org\r\n" |
| 12278 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12279 | |
| 12280 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12281 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 12282 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 12283 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12284 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12285 | MockRead("Payload"), |
| 12286 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12287 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12288 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12291 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12292 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12293 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12295 | |
| 12296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12297 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12299 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12300 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12301 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12302 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12303 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12304 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12305 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12306 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 12307 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12308 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12309 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12310 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12311 | EXPECT_EQ("Payload", response_text); |
| 12312 | } |
| 12313 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12314 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12315 | HttpRequestInfo request; |
| 12316 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12317 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12318 | request.traffic_annotation = |
| 12319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12320 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12321 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12322 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12323 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 12324 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12325 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12329 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12330 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 12331 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12332 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12333 | 0x05, // Version |
| 12334 | 0x01, // Command (CONNECT) |
| 12335 | 0x00, // Reserved. |
| 12336 | 0x03, // Address type (DOMAINNAME). |
| 12337 | 0x0F, // Length of domain (15) |
| 12338 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 12339 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 12340 | }; |
| 12341 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12342 | const char kSOCKS5OkResponse[] = |
| 12343 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 12344 | |
| 12345 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12346 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12347 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12348 | base::size(kSOCKS5OkRequest)), |
| 12349 | MockWrite("GET / HTTP/1.1\r\n" |
| 12350 | "Host: www.example.org\r\n" |
| 12351 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 12352 | |
| 12353 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12354 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 12355 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 12356 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 12357 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 12358 | MockRead("Payload"), |
| 12359 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12360 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12361 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12363 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12364 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12367 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12369 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12371 | |
| 12372 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12373 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12375 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12376 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12377 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12378 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12379 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12380 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12381 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12382 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12383 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12384 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12385 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12386 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 12387 | EXPECT_EQ("Payload", response_text); |
| 12388 | } |
| 12389 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12390 | namespace { |
| 12391 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12392 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12393 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12394 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12395 | std::string proxy_server; |
| 12396 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12397 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 12398 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12399 | }; |
| 12400 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12401 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12402 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12404 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12405 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12406 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12407 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12408 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12409 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 12410 | url::SchemeHostPort("https", "host.with.alternate", 443), |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12411 | NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12412 | |
| 12413 | return session; |
| 12414 | } |
| 12415 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12416 | int GroupIdTransactionHelper(const std::string& url, |
| 12417 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12418 | HttpRequestInfo request; |
| 12419 | request.method = "GET"; |
| 12420 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12421 | request.traffic_annotation = |
| 12422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12423 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12424 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12426 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12427 | |
| 12428 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12429 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12430 | } |
| 12431 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12432 | } // namespace |
| 12433 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12434 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 12435 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12436 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12437 | "", // unused |
| 12438 | "http://www.example.org/direct", |
| 12439 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12440 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12441 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12442 | NetworkIsolationKey(), |
| 12443 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12444 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12445 | }, |
| 12446 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12447 | "", // unused |
| 12448 | "http://[2001:1418:13:1::25]/direct", |
| 12449 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 12450 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12451 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12452 | NetworkIsolationKey(), |
| 12453 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12454 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12455 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12456 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12457 | // SSL Tests |
| 12458 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12459 | "", // unused |
| 12460 | "https://www.example.org/direct_ssl", |
| 12461 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12462 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12463 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12464 | NetworkIsolationKey(), |
| 12465 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12466 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12467 | }, |
| 12468 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12469 | "", // unused |
| 12470 | "https://[2001:1418:13:1::25]/direct", |
| 12471 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 12472 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12473 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12474 | NetworkIsolationKey(), |
| 12475 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12476 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12477 | }, |
| 12478 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12479 | "", // unused |
| 12480 | "https://host.with.alternate/direct", |
| 12481 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 12482 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12483 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12484 | NetworkIsolationKey(), |
| 12485 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12486 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12487 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12488 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12489 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12490 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12491 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12492 | ConfiguredProxyResolutionService::CreateFixed( |
| 12493 | tests[i].proxy_server, TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12494 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12495 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12496 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12497 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12498 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 12499 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12500 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 12501 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 12502 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12503 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12504 | |
| 12505 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12506 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 12507 | EXPECT_EQ(tests[i].expected_group_id, |
| 12508 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 12509 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12510 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12511 | } |
| 12512 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12513 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 12514 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12515 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12516 | "http_proxy", |
| 12517 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12518 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12519 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12520 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12521 | NetworkIsolationKey(), |
| 12522 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12523 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12524 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12525 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12526 | // SSL Tests |
| 12527 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12528 | "http_proxy", |
| 12529 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12530 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12531 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12532 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12533 | NetworkIsolationKey(), |
| 12534 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12535 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12536 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 12537 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12538 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12539 | "http_proxy", |
| 12540 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12541 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 12542 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12543 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12544 | NetworkIsolationKey(), |
| 12545 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12546 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12547 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12548 | }; |
| 12549 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12550 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12551 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12552 | ConfiguredProxyResolutionService::CreateFixed( |
| 12553 | tests[i].proxy_server, TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12554 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12555 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12556 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12557 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12558 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 12559 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12560 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12561 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 12562 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12563 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 12564 | mock_pool_manager->SetSocketPool(proxy_server, |
| 12565 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12566 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12567 | |
| 12568 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12569 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 12570 | EXPECT_EQ(tests[i].expected_group_id, |
| 12571 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12572 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12573 | } |
| 12574 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12575 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 12576 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12577 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12578 | "socks4://socks_proxy:1080", |
| 12579 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12580 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12581 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12582 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12583 | NetworkIsolationKey(), |
| 12584 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12585 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12586 | }, |
| 12587 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12588 | "socks5://socks_proxy:1080", |
| 12589 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12590 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 12591 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12592 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12593 | NetworkIsolationKey(), |
| 12594 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12595 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12596 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12597 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12598 | // SSL Tests |
| 12599 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12600 | "socks4://socks_proxy:1080", |
| 12601 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12602 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12603 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12604 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12605 | NetworkIsolationKey(), |
| 12606 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12607 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12608 | }, |
| 12609 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12610 | "socks5://socks_proxy:1080", |
| 12611 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12612 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 12613 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12614 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12615 | NetworkIsolationKey(), |
| 12616 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12617 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12618 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 12619 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12620 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12621 | "socks4://socks_proxy:1080", |
| 12622 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12623 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 12624 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 12625 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 12626 | NetworkIsolationKey(), |
| 12627 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 12628 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12629 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12630 | }; |
| 12631 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 12632 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12633 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12634 | ConfiguredProxyResolutionService::CreateFixed( |
| 12635 | tests[i].proxy_server, TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12636 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12637 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 12638 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12639 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12640 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 12641 | ProxyServer proxy_server( |
| 12642 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 12643 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12644 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 12645 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12646 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 12647 | mock_pool_manager->SetSocketPool(proxy_server, |
| 12648 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12649 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12652 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 12653 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 12654 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 12655 | EXPECT_EQ(tests[i].expected_group_id, |
| 12656 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 12657 | } |
| 12658 | } |
| 12659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12660 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12661 | HttpRequestInfo request; |
| 12662 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12663 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12664 | request.traffic_annotation = |
| 12665 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12666 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12667 | session_deps_.proxy_resolution_service = |
| 12668 | ConfiguredProxyResolutionService::CreateFixed( |
| 12669 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 12670 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 12671 | // This simulates failure resolving all hostnames; that means we will fail |
| 12672 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12673 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 12674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12677 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12678 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12680 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12682 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12683 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12684 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 12685 | } |
| 12686 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12687 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12688 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12689 | HttpRequestInfo request; |
| 12690 | request.method = "GET"; |
| 12691 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12692 | request.traffic_annotation = |
| 12693 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12694 | |
| 12695 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12696 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12697 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12698 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12702 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12706 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12708 | |
| 12709 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12710 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12711 | |
| 12712 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12713 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12714 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12715 | } |
| 12716 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12717 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12718 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12719 | HttpRequestInfo request; |
| 12720 | request.method = "GET"; |
| 12721 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12722 | request.traffic_annotation = |
| 12723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12724 | |
| 12725 | MockRead data_reads[] = { |
| 12726 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12727 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12728 | }; |
| 12729 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12730 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12731 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12734 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12740 | |
| 12741 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12742 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12745 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12746 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12747 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12748 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 12749 | |
| 12750 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12751 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12752 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 12753 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12754 | |
| 12755 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12756 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 12757 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12758 | } |
| 12759 | |
| 12760 | // Make sure that a dropped connection while draining the body for auth |
| 12761 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12762 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12763 | HttpRequestInfo request; |
| 12764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12765 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12766 | request.traffic_annotation = |
| 12767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12768 | |
| 12769 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12770 | MockWrite( |
| 12771 | "GET / HTTP/1.1\r\n" |
| 12772 | "Host: www.example.org\r\n" |
| 12773 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12774 | }; |
| 12775 | |
| 12776 | MockRead data_reads1[] = { |
| 12777 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 12778 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 12779 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12780 | MockRead("Content-Length: 14\r\n\r\n"), |
| 12781 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12782 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12783 | }; |
| 12784 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12785 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12786 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12788 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12789 | // be issuing -- the final header line contains the credentials. |
| 12790 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12791 | MockWrite( |
| 12792 | "GET / HTTP/1.1\r\n" |
| 12793 | "Host: www.example.org\r\n" |
| 12794 | "Connection: keep-alive\r\n" |
| 12795 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12796 | }; |
| 12797 | |
| 12798 | // Lastly, the server responds with the actual content. |
| 12799 | MockRead data_reads2[] = { |
| 12800 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12801 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12802 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12804 | }; |
| 12805 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12806 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12810 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12811 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12813 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12814 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12816 | |
| 12817 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12818 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12820 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12821 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12822 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12824 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12826 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12828 | |
| 12829 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12832 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12833 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12834 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12835 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12836 | } |
| 12837 | |
| 12838 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12839 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 12840 | session_deps_.proxy_resolution_service = |
| 12841 | ConfiguredProxyResolutionService::CreateFixed( |
| 12842 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12843 | |
| 12844 | HttpRequestInfo request; |
| 12845 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12846 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12847 | request.traffic_annotation = |
| 12848 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12849 | |
| 12850 | MockRead proxy_reads[] = { |
| 12851 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12852 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12853 | }; |
| 12854 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12855 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12856 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12857 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12860 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12861 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12862 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12863 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12867 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12868 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12870 | |
| 12871 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12872 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 12873 | } |
| 12874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12875 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12876 | HttpRequestInfo request; |
| 12877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12878 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12879 | request.traffic_annotation = |
| 12880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12881 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12883 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12884 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 12885 | MockRead data_reads[] = { |
| 12886 | 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] | 12887 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 12888 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12889 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12890 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12891 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12893 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12895 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12897 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12898 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12900 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12901 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12902 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12903 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 12904 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 12905 | |
| 12906 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12907 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12908 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 12909 | } |
| 12910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12911 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 12912 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 12913 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12914 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 12915 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 12916 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12917 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12918 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12919 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12920 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 12921 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12922 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12923 | |
| 12924 | HttpRequestInfo request; |
| 12925 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12926 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12927 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12928 | request.traffic_annotation = |
| 12929 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12933 | |
| 12934 | MockRead data_reads[] = { |
| 12935 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 12936 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12937 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12938 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12939 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12942 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12943 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12944 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12946 | |
| 12947 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12948 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12950 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12951 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12952 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 12953 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12954 | |
Lei Zhang | 6dfdc9b1 | 2020-06-29 22:15:31 | [diff] [blame] | 12955 | base::DeleteFile(temp_file_path); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12956 | } |
| 12957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12958 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 12959 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 12960 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12961 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 12962 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 12963 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 12964 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 12965 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12966 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12967 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12968 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12969 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 12970 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12971 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12972 | |
| 12973 | HttpRequestInfo request; |
| 12974 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12975 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12976 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12977 | request.traffic_annotation = |
| 12978 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12979 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 12980 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12982 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12983 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12984 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12987 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12988 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12989 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12991 | |
| 12992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12993 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12994 | |
Lei Zhang | 6dfdc9b1 | 2020-06-29 22:15:31 | [diff] [blame] | 12995 | base::DeleteFile(temp_file); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12996 | } |
| 12997 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12998 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12999 | class FakeUploadElementReader : public UploadElementReader { |
| 13000 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13001 | FakeUploadElementReader() = default; |
| 13002 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13003 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 13004 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13005 | |
| 13006 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 13007 | int Init(CompletionOnceCallback callback) override { |
| 13008 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13009 | return ERR_IO_PENDING; |
| 13010 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 13011 | uint64_t GetContentLength() const override { return 0; } |
| 13012 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13013 | int Read(IOBuffer* buf, |
| 13014 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 13015 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13016 | return ERR_FAILED; |
| 13017 | } |
| 13018 | |
| 13019 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 13020 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13021 | }; |
| 13022 | |
| 13023 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13024 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 13025 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 13026 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13027 | |
| 13028 | HttpRequestInfo request; |
| 13029 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13030 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13031 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13032 | request.traffic_annotation = |
| 13033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13036 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13037 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13038 | |
| 13039 | StaticSocketDataProvider data; |
| 13040 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13041 | |
| 13042 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13043 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13045 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13046 | |
| 13047 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 13048 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 13049 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13050 | |
| 13051 | // Return Init()'s result after the transaction gets destroyed. |
| 13052 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 13053 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 13054 | } |
| 13055 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13056 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13057 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13058 | HttpRequestInfo request; |
| 13059 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13060 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13061 | request.traffic_annotation = |
| 13062 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13063 | |
| 13064 | // First transaction will request a resource and receive a Basic challenge |
| 13065 | // with realm="first_realm". |
| 13066 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13067 | MockWrite( |
| 13068 | "GET / HTTP/1.1\r\n" |
| 13069 | "Host: www.example.org\r\n" |
| 13070 | "Connection: keep-alive\r\n" |
| 13071 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13072 | }; |
| 13073 | MockRead data_reads1[] = { |
| 13074 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 13075 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 13076 | "\r\n"), |
| 13077 | }; |
| 13078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13079 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13080 | // for first_realm. The server will reject and provide a challenge with |
| 13081 | // second_realm. |
| 13082 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13083 | MockWrite( |
| 13084 | "GET / HTTP/1.1\r\n" |
| 13085 | "Host: www.example.org\r\n" |
| 13086 | "Connection: keep-alive\r\n" |
| 13087 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 13088 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13089 | }; |
| 13090 | MockRead data_reads2[] = { |
| 13091 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 13092 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 13093 | "\r\n"), |
| 13094 | }; |
| 13095 | |
| 13096 | // This again fails, and goes back to first_realm. Make sure that the |
| 13097 | // entry is removed from cache. |
| 13098 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13099 | MockWrite( |
| 13100 | "GET / HTTP/1.1\r\n" |
| 13101 | "Host: www.example.org\r\n" |
| 13102 | "Connection: keep-alive\r\n" |
| 13103 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 13104 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13105 | }; |
| 13106 | MockRead data_reads3[] = { |
| 13107 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 13108 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 13109 | "\r\n"), |
| 13110 | }; |
| 13111 | |
| 13112 | // Try one last time (with the correct password) and get the resource. |
| 13113 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13114 | MockWrite( |
| 13115 | "GET / HTTP/1.1\r\n" |
| 13116 | "Host: www.example.org\r\n" |
| 13117 | "Connection: keep-alive\r\n" |
| 13118 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 13119 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13120 | }; |
| 13121 | MockRead data_reads4[] = { |
| 13122 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13123 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13124 | "Content-Length: 5\r\n" |
| 13125 | "\r\n" |
| 13126 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13127 | }; |
| 13128 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13129 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 13130 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 13131 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 13132 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13133 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13134 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13135 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 13136 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13138 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13139 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13140 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13141 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13142 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13143 | // Issue the first request with Authorize headers. There should be a |
| 13144 | // password prompt for first_realm waiting to be filled in after the |
| 13145 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13146 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13147 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13148 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13149 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13150 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13151 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 13152 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13153 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 13154 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 13155 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 13156 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 13157 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13158 | |
| 13159 | // Issue the second request with an incorrect password. There should be a |
| 13160 | // password prompt for second_realm waiting to be filled in after the |
| 13161 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13162 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13163 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 13164 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13165 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13166 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13167 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13168 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13169 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 13170 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13171 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 13172 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 13173 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 13174 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 13175 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13176 | |
| 13177 | // Issue the third request with another incorrect password. There should be |
| 13178 | // a password prompt for first_realm waiting to be filled in. If the password |
| 13179 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 13180 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13181 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13182 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 13183 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13185 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13186 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13187 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13188 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 13189 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13190 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 13191 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 13192 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 13193 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 13194 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13195 | |
| 13196 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13197 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13198 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 13199 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13200 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13201 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13202 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13203 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13204 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 13205 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 13206 | } |
| 13207 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13208 | // Regression test for https://crbug.com/754395. |
| 13209 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 13210 | MockRead data_reads[] = { |
| 13211 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13212 | MockRead(kAlternativeServiceHttpHeader), |
| 13213 | MockRead("\r\n"), |
| 13214 | MockRead("hello world"), |
| 13215 | MockRead(SYNCHRONOUS, OK), |
| 13216 | }; |
| 13217 | |
| 13218 | HttpRequestInfo request; |
| 13219 | request.method = "GET"; |
| 13220 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13221 | request.traffic_annotation = |
| 13222 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13223 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13224 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13225 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13226 | |
| 13227 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13228 | ssl.ssl_info.cert = |
| 13229 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13230 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 13231 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13233 | |
| 13234 | TestCompletionCallback callback; |
| 13235 | |
| 13236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13238 | |
| 13239 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 13240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13241 | |
| 13242 | url::SchemeHostPort test_server(request.url); |
| 13243 | HttpServerProperties* http_server_properties = |
| 13244 | session->http_server_properties(); |
| 13245 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13246 | http_server_properties |
| 13247 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13248 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13249 | |
| 13250 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13251 | |
| 13252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13253 | ASSERT_TRUE(response); |
| 13254 | ASSERT_TRUE(response->headers); |
| 13255 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13256 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13257 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 13258 | |
| 13259 | std::string response_data; |
| 13260 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13261 | EXPECT_EQ("hello world", response_data); |
| 13262 | |
| 13263 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13264 | http_server_properties |
| 13265 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13266 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 13267 | } |
| 13268 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13269 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13270 | MockRead data_reads[] = { |
| 13271 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13272 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13273 | MockRead("\r\n"), |
| 13274 | MockRead("hello world"), |
| 13275 | MockRead(SYNCHRONOUS, OK), |
| 13276 | }; |
| 13277 | |
| 13278 | HttpRequestInfo request; |
| 13279 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13280 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13281 | request.traffic_annotation = |
| 13282 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13283 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13284 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13286 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13287 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13288 | ssl.ssl_info.cert = |
| 13289 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13290 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13291 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13292 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13293 | TestCompletionCallback callback; |
| 13294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13298 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13300 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13301 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13302 | HttpServerProperties* http_server_properties = |
| 13303 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13304 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13305 | http_server_properties |
| 13306 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13307 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13308 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13309 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13311 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13312 | ASSERT_TRUE(response); |
| 13313 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13314 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13315 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13316 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13317 | |
| 13318 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13319 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13320 | EXPECT_EQ("hello world", response_data); |
| 13321 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13322 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13323 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 13324 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13325 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 13326 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 13327 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13328 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13329 | } |
| 13330 | |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13331 | TEST_F(HttpNetworkTransactionTest, |
| 13332 | HonorAlternativeServiceHeaderWithNetworkIsolationKey) { |
| 13333 | base::test::ScopedFeatureList feature_list; |
| 13334 | feature_list.InitWithFeatures( |
| 13335 | // enabled_features |
| 13336 | {features::kPartitionHttpServerPropertiesByNetworkIsolationKey, |
| 13337 | // Need to partition connections by NetworkIsolationKey for |
| 13338 | // SpdySessionKeys to include NetworkIsolationKeys. |
| 13339 | features::kPartitionConnectionsByNetworkIsolationKey}, |
| 13340 | // disabled_features |
| 13341 | {}); |
| 13342 | // Since HttpServerProperties caches the feature value, have to create a new |
| 13343 | // one. |
| 13344 | session_deps_.http_server_properties = |
| 13345 | std::make_unique<HttpServerProperties>(); |
| 13346 | |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 13347 | const SchemefulSite kSite1(GURL("https://foo.test/")); |
| 13348 | const net::NetworkIsolationKey kNetworkIsolationKey1(kSite1, kSite1); |
| 13349 | const SchemefulSite kSite2(GURL("https://bar.test/")); |
| 13350 | const net::NetworkIsolationKey kNetworkIsolationKey2(kSite2, kSite2); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13351 | |
| 13352 | MockRead data_reads[] = { |
| 13353 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13354 | MockRead(kAlternativeServiceHttpHeader), |
| 13355 | MockRead("\r\n"), |
| 13356 | MockRead("hello world"), |
| 13357 | MockRead(SYNCHRONOUS, OK), |
| 13358 | }; |
| 13359 | |
| 13360 | HttpRequestInfo request; |
| 13361 | request.method = "GET"; |
| 13362 | request.url = GURL("https://www.example.org/"); |
| 13363 | request.traffic_annotation = |
| 13364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 13365 | request.network_isolation_key = kNetworkIsolationKey1; |
| 13366 | |
| 13367 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 13368 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13369 | |
| 13370 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13371 | ssl.ssl_info.cert = |
| 13372 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13373 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 13374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13375 | |
| 13376 | TestCompletionCallback callback; |
| 13377 | |
| 13378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13380 | |
| 13381 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 13382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13383 | |
| 13384 | url::SchemeHostPort test_server(request.url); |
| 13385 | HttpServerProperties* http_server_properties = |
| 13386 | session->http_server_properties(); |
| 13387 | EXPECT_TRUE( |
| 13388 | http_server_properties |
| 13389 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey1) |
| 13390 | .empty()); |
| 13391 | |
| 13392 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13393 | |
| 13394 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13395 | ASSERT_TRUE(response); |
| 13396 | ASSERT_TRUE(response->headers); |
| 13397 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13398 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13399 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 13400 | |
| 13401 | std::string response_data; |
| 13402 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13403 | EXPECT_EQ("hello world", response_data); |
| 13404 | |
| 13405 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 13406 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 13407 | kNetworkIsolationKey1); |
| 13408 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 13409 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 13410 | EXPECT_EQ(alternative_service, |
| 13411 | alternative_service_info_vector[0].alternative_service()); |
| 13412 | |
| 13413 | // Make sure the alternative service information is only associated with |
| 13414 | // kNetworkIsolationKey1. |
| 13415 | EXPECT_TRUE( |
| 13416 | http_server_properties |
| 13417 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13418 | .empty()); |
| 13419 | EXPECT_TRUE( |
| 13420 | http_server_properties |
| 13421 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey2) |
| 13422 | .empty()); |
| 13423 | } |
| 13424 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13425 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13426 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13427 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13428 | MockRead data_reads[] = { |
| 13429 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13430 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13431 | MockRead("\r\n"), |
| 13432 | MockRead("hello world"), |
| 13433 | MockRead(SYNCHRONOUS, OK), |
| 13434 | }; |
| 13435 | |
| 13436 | HttpRequestInfo request; |
| 13437 | request.method = "GET"; |
| 13438 | request.url = GURL("http://www.example.org/"); |
| 13439 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13440 | request.traffic_annotation = |
| 13441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13442 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13443 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13444 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13445 | |
| 13446 | TestCompletionCallback callback; |
| 13447 | |
| 13448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13450 | |
| 13451 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13452 | HttpServerProperties* http_server_properties = |
| 13453 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13454 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13455 | http_server_properties |
| 13456 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13457 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13458 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13459 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13461 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13462 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13463 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13464 | ASSERT_TRUE(response); |
| 13465 | ASSERT_TRUE(response->headers); |
| 13466 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13467 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13468 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13469 | |
| 13470 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13471 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13472 | EXPECT_EQ("hello world", response_data); |
| 13473 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13474 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13475 | http_server_properties |
| 13476 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13477 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13478 | } |
| 13479 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 13480 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13481 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13482 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13483 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 13484 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13485 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13486 | HttpRequestInfo request; |
| 13487 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13488 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13489 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13490 | request.traffic_annotation = |
| 13491 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13492 | |
| 13493 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13494 | StaticSocketDataProvider first_data; |
| 13495 | first_data.set_connect_data(mock_connect); |
| 13496 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13497 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13498 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13500 | |
| 13501 | MockRead data_reads[] = { |
| 13502 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 13503 | MockRead(ASYNC, OK), |
| 13504 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13505 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13506 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 13507 | |
| 13508 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13509 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13510 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13511 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13512 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 13513 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13514 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13515 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13516 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13517 | alternative_service, expiration); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13520 | TestCompletionCallback callback; |
| 13521 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13522 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13523 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13524 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13525 | } |
| 13526 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13527 | // Regression test for https://crbug.com/615497: |
| 13528 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13529 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13530 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13531 | HttpRequestInfo request; |
| 13532 | request.method = "GET"; |
| 13533 | request.url = GURL("http://www.example.org/"); |
| 13534 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13535 | request.traffic_annotation = |
| 13536 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13537 | |
| 13538 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13539 | StaticSocketDataProvider first_data; |
| 13540 | first_data.set_connect_data(mock_connect); |
| 13541 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 13542 | |
| 13543 | MockRead data_reads[] = { |
| 13544 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 13545 | MockRead(ASYNC, OK), |
| 13546 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13547 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13548 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 13549 | |
| 13550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13551 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13552 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13553 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13554 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13555 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13556 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13557 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13558 | alternative_service, expiration); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13560 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13561 | TestCompletionCallback callback; |
| 13562 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13563 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13564 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13565 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 13566 | } |
| 13567 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13568 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13569 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13570 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13571 | HttpServerProperties* http_server_properties = |
| 13572 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13573 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13574 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13575 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13576 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13577 | test_server, NetworkIsolationKey(), alternative_service, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13578 | session->context().quic_context->params()->supported_versions); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13579 | EXPECT_EQ(1u, |
| 13580 | http_server_properties |
| 13581 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13582 | .size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13583 | |
| 13584 | // Send a clear header. |
| 13585 | MockRead data_reads[] = { |
| 13586 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13587 | MockRead("Alt-Svc: clear\r\n"), |
| 13588 | MockRead("\r\n"), |
| 13589 | MockRead("hello world"), |
| 13590 | MockRead(SYNCHRONOUS, OK), |
| 13591 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13592 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13594 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13595 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13596 | ssl.ssl_info.cert = |
| 13597 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13598 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13599 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13600 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13601 | HttpRequestInfo request; |
| 13602 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13603 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13604 | request.traffic_annotation = |
| 13605 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13606 | |
| 13607 | TestCompletionCallback callback; |
| 13608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13610 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13611 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13612 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [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); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13617 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13618 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13619 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13620 | |
| 13621 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13622 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13623 | EXPECT_EQ("hello world", response_data); |
| 13624 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13625 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13626 | http_server_properties |
| 13627 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13628 | .empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 13629 | } |
| 13630 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13631 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13632 | MockRead data_reads[] = { |
| 13633 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13634 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 13635 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13636 | MockRead("hello world"), |
| 13637 | MockRead(SYNCHRONOUS, OK), |
| 13638 | }; |
| 13639 | |
| 13640 | HttpRequestInfo request; |
| 13641 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13642 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13643 | request.traffic_annotation = |
| 13644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13645 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13646 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13648 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13649 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13650 | ssl.ssl_info.cert = |
| 13651 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13652 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13653 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13654 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13655 | TestCompletionCallback callback; |
| 13656 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13657 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13658 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13659 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13660 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13662 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13663 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13664 | HttpServerProperties* http_server_properties = |
| 13665 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13666 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13667 | http_server_properties |
| 13668 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 13669 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13670 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13671 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13673 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13674 | ASSERT_TRUE(response); |
| 13675 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13676 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13677 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13678 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13679 | |
| 13680 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13681 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13682 | EXPECT_EQ("hello world", response_data); |
| 13683 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13684 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13685 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 13686 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13687 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 13688 | |
| 13689 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 13690 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13691 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13692 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 13693 | 1234); |
| 13694 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13695 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13696 | } |
| 13697 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13698 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13699 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13700 | HostPortPair alternative("alternative.example.org", 443); |
| 13701 | std::string origin_url = "https://origin.example.org:443"; |
| 13702 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13703 | |
| 13704 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13705 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13706 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13708 | |
| 13709 | // HTTP/1.1 data for request. |
| 13710 | MockWrite http_writes[] = { |
| 13711 | MockWrite("GET / HTTP/1.1\r\n" |
| 13712 | "Host: alternative.example.org\r\n" |
| 13713 | "Connection: keep-alive\r\n\r\n"), |
| 13714 | }; |
| 13715 | |
| 13716 | MockRead http_reads[] = { |
| 13717 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13718 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13719 | "Content-Length: 40\r\n\r\n" |
| 13720 | "first HTTP/1.1 response from alternative"), |
| 13721 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13722 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13723 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13724 | |
| 13725 | StaticSocketDataProvider data_refused; |
| 13726 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13727 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13728 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13729 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13730 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13731 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13732 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13733 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13734 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13735 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13736 | server, NetworkIsolationKey(), alternative_service, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13737 | DefaultSupportedQuicVersions()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13738 | // Mark the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 13739 | http_server_properties->MarkAlternativeServiceBroken(alternative_service, |
| 13740 | NetworkIsolationKey()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13741 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13742 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13743 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13744 | request.method = "GET"; |
| 13745 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13746 | request.traffic_annotation = |
| 13747 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 13748 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13749 | TestCompletionCallback callback; |
| 13750 | NetErrorDetails details; |
| 13751 | EXPECT_FALSE(details.quic_broken); |
| 13752 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13753 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13754 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13755 | EXPECT_TRUE(details.quic_broken); |
| 13756 | } |
| 13757 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13758 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13759 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13760 | HostPortPair alternative1("alternative1.example.org", 443); |
| 13761 | HostPortPair alternative2("alternative2.example.org", 443); |
| 13762 | std::string origin_url = "https://origin.example.org:443"; |
| 13763 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 13764 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 13765 | |
| 13766 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 13767 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13768 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13770 | |
| 13771 | // HTTP/1.1 data for request. |
| 13772 | MockWrite http_writes[] = { |
| 13773 | MockWrite("GET / HTTP/1.1\r\n" |
| 13774 | "Host: alternative1.example.org\r\n" |
| 13775 | "Connection: keep-alive\r\n\r\n"), |
| 13776 | }; |
| 13777 | |
| 13778 | MockRead http_reads[] = { |
| 13779 | MockRead("HTTP/1.1 200 OK\r\n" |
| 13780 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13781 | "Content-Length: 40\r\n\r\n" |
| 13782 | "first HTTP/1.1 response from alternative1"), |
| 13783 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13784 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13785 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13786 | |
| 13787 | StaticSocketDataProvider data_refused; |
| 13788 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13789 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13790 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13792 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13793 | session->http_server_properties(); |
| 13794 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13795 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13796 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 13797 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 13798 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13799 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13800 | alternative_service_info_vector.push_back( |
| 13801 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 13802 | alternative_service1, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13803 | session->context().quic_context->params()->supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13804 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13805 | alternative_service_info_vector.push_back( |
| 13806 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 13807 | alternative_service2, expiration, |
Victor Vasiliev | a1e66d7 | 2019-12-05 17:55:38 | [diff] [blame] | 13808 | session->context().quic_context->params()->supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13809 | |
| 13810 | http_server_properties->SetAlternativeServices( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13811 | server, NetworkIsolationKey(), alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13812 | |
| 13813 | // Mark one of the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 13814 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1, |
| 13815 | NetworkIsolationKey()); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13816 | EXPECT_EQ(2u, http_server_properties |
| 13817 | ->GetAlternativeServiceInfos(server, NetworkIsolationKey()) |
| 13818 | .size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13819 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13820 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 13821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13822 | request.method = "GET"; |
| 13823 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13824 | request.traffic_annotation = |
| 13825 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 13826 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13827 | TestCompletionCallback callback; |
| 13828 | NetErrorDetails details; |
| 13829 | EXPECT_FALSE(details.quic_broken); |
| 13830 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13831 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13832 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 13833 | EXPECT_FALSE(details.quic_broken); |
| 13834 | } |
| 13835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13836 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13837 | HttpRequestInfo request; |
| 13838 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13839 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13840 | request.traffic_annotation = |
| 13841 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13842 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13843 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13844 | StaticSocketDataProvider first_data; |
| 13845 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13846 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13847 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13848 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [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] | 564b491 | 2010-03-09 16:30:42 | [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] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13860 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13861 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13862 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13863 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13864 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 13865 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13866 | // Port is ignored by MockConnect anyway. |
| 13867 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13868 | 666); |
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 | server, NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13873 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13874 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13875 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13876 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13878 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13880 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13881 | ASSERT_TRUE(response); |
| 13882 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13883 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13884 | |
| 13885 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13886 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13887 | EXPECT_EQ("hello world", response_data); |
| 13888 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13889 | const AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 13890 | http_server_properties->GetAlternativeServiceInfos(server, |
| 13891 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 13892 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 13893 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 13894 | alternative_service_info_vector[0].alternative_service()); |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 13895 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 13896 | alternative_service, NetworkIsolationKey())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13897 | } |
| 13898 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13899 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13900 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13901 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13902 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13903 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13904 | HttpRequestInfo restricted_port_request; |
| 13905 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13906 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13907 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13908 | restricted_port_request.traffic_annotation = |
| 13909 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13910 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13911 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13912 | StaticSocketDataProvider first_data; |
| 13913 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13914 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13915 | |
| 13916 | MockRead data_reads[] = { |
| 13917 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13918 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13919 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13920 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13921 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13922 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13923 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13924 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13925 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13926 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13928 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13929 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13930 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13931 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13932 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13933 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13934 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13935 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13936 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13937 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13940 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13942 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 13943 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13945 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13946 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13947 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13948 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13949 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 13950 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 13951 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13952 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13953 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13954 | |
| 13955 | HttpRequestInfo restricted_port_request; |
| 13956 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13957 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13958 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13959 | restricted_port_request.traffic_annotation = |
| 13960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13961 | |
| 13962 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13963 | StaticSocketDataProvider first_data; |
| 13964 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13965 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13966 | |
| 13967 | MockRead data_reads[] = { |
| 13968 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13969 | MockRead("hello world"), |
| 13970 | MockRead(ASYNC, OK), |
| 13971 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13972 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13973 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13974 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13975 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13976 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13979 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13980 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13981 | session->http_server_properties(); |
| 13982 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13983 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13984 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13985 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13986 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13987 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13988 | alternative_service, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13990 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13991 | TestCompletionCallback callback; |
| 13992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13993 | EXPECT_EQ(ERR_IO_PENDING, |
| 13994 | trans.Start(&restricted_port_request, callback.callback(), |
| 13995 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13996 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13997 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13998 | } |
| 13999 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14000 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 14001 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 14002 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 14003 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14004 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14005 | HttpRequestInfo restricted_port_request; |
| 14006 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14007 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14008 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14009 | restricted_port_request.traffic_annotation = |
| 14010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14011 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14012 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14013 | StaticSocketDataProvider first_data; |
| 14014 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14015 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14016 | |
| 14017 | MockRead data_reads[] = { |
| 14018 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 14019 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14020 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14021 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14022 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14023 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14024 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14025 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14026 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14029 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14030 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 14031 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14032 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14033 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 14034 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14035 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14036 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 14037 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 14038 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14041 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14043 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 14044 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14046 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14047 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14048 | } |
| 14049 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14050 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 14051 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 14052 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 14053 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14054 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14055 | HttpRequestInfo unrestricted_port_request; |
| 14056 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14057 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14058 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14059 | unrestricted_port_request.traffic_annotation = |
| 14060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14061 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14062 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14063 | StaticSocketDataProvider first_data; |
| 14064 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14065 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14066 | |
| 14067 | MockRead data_reads[] = { |
| 14068 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 14069 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14070 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14071 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14072 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14073 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14074 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14075 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14076 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14079 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14080 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 14081 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14082 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14083 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 14084 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14085 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14086 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 14087 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 14088 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14091 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14093 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14094 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14096 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14097 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14098 | } |
| 14099 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14100 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 14101 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 14102 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 14103 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14104 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14105 | HttpRequestInfo unrestricted_port_request; |
| 14106 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14107 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14108 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14109 | unrestricted_port_request.traffic_annotation = |
| 14110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14111 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14112 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14113 | StaticSocketDataProvider first_data; |
| 14114 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14115 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14116 | |
| 14117 | MockRead data_reads[] = { |
| 14118 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 14119 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14120 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14121 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14122 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14123 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14124 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14125 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14129 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14130 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 14131 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 14132 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14133 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 14134 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14135 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14136 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 14137 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 14138 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14139 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14140 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14141 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14143 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14144 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14145 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14146 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14147 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 14148 | } |
| 14149 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14150 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 14151 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 14152 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14153 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14154 | HttpRequestInfo request; |
| 14155 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14156 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14157 | request.traffic_annotation = |
| 14158 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14159 | |
| 14160 | // The alternate protocol request will error out before we attempt to connect, |
| 14161 | // so only the standard HTTP request will try to connect. |
| 14162 | MockRead data_reads[] = { |
| 14163 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 14164 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14165 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14166 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14167 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14168 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14169 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14171 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14172 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14173 | session->http_server_properties(); |
| 14174 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14175 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 14176 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14177 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14178 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 14179 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 14180 | alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14183 | TestCompletionCallback callback; |
| 14184 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14185 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14186 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14187 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14188 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14190 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14191 | ASSERT_TRUE(response); |
| 14192 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14193 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14194 | |
| 14195 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14196 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 14197 | EXPECT_EQ("hello world", response_data); |
| 14198 | } |
| 14199 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14200 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14201 | HttpRequestInfo request; |
| 14202 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14203 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14204 | request.traffic_annotation = |
| 14205 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14206 | |
| 14207 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14208 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14209 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14210 | MockRead("\r\n"), |
| 14211 | MockRead("hello world"), |
| 14212 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14213 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14214 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14215 | StaticSocketDataProvider first_transaction(data_reads, |
| 14216 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14217 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14218 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14219 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14220 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14221 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14222 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14223 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14224 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14225 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14226 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14227 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14228 | spdy::SpdySerializedFrame resp( |
| 14229 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14230 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14231 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14232 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14233 | }; |
| 14234 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14235 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14236 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14237 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14238 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14239 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14240 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 14241 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14242 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14243 | &hanging_non_alternate_protocol_socket); |
| 14244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14245 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14248 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14249 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14250 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14251 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14253 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14254 | |
| 14255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14256 | ASSERT_TRUE(response); |
| 14257 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14258 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14259 | |
| 14260 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14261 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14262 | EXPECT_EQ("hello world", response_data); |
| 14263 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14264 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14265 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14266 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14267 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14268 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14269 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14270 | |
| 14271 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14272 | ASSERT_TRUE(response); |
| 14273 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14274 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14275 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14276 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14277 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14278 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14279 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14280 | } |
| 14281 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14282 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14283 | HttpRequestInfo request; |
| 14284 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14285 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14286 | request.traffic_annotation = |
| 14287 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14288 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14289 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14290 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14291 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14292 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14293 | MockRead("\r\n"), |
| 14294 | MockRead("hello world"), |
| 14295 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14296 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14297 | }; |
| 14298 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14299 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14300 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14301 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14302 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 14303 | ssl_http11.ssl_info.cert = |
| 14304 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 14305 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 14307 | |
| 14308 | // Second transaction starts an alternative and a non-alternative Job. |
| 14309 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14310 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14311 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14312 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14313 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 14314 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14315 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14316 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 14317 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14318 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14319 | // Third transaction starts an alternative and a non-alternative job. |
| 14320 | // The non-alternative job hangs, but the alternative one succeeds. |
| 14321 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14322 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14323 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14324 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14325 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14326 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14327 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14328 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14329 | spdy::SpdySerializedFrame resp1( |
| 14330 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14331 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14332 | spdy::SpdySerializedFrame resp2( |
| 14333 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14334 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14335 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14336 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 14337 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14338 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14339 | }; |
| 14340 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14341 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14342 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14343 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14344 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14345 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14346 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14347 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 14348 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14351 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14352 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14354 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14356 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14357 | |
| 14358 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14359 | ASSERT_TRUE(response); |
| 14360 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14361 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14362 | |
| 14363 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14364 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14365 | EXPECT_EQ("hello world", response_data); |
| 14366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14367 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14368 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14369 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14372 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14373 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14374 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14376 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14377 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 14378 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14379 | |
| 14380 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14381 | ASSERT_TRUE(response); |
| 14382 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14383 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14384 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14385 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14386 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14387 | EXPECT_EQ("hello!", response_data); |
| 14388 | |
| 14389 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14390 | ASSERT_TRUE(response); |
| 14391 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14392 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14393 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14394 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14395 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14396 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14397 | } |
| 14398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14399 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 14400 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 14401 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14402 | HttpRequestInfo request; |
| 14403 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14404 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14405 | request.traffic_annotation = |
| 14406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14407 | |
| 14408 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14409 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14410 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14411 | MockRead("\r\n"), |
| 14412 | MockRead("hello world"), |
| 14413 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14414 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14415 | }; |
| 14416 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14417 | StaticSocketDataProvider first_transaction(data_reads, |
| 14418 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14419 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14420 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14421 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 14422 | ssl.ssl_info.cert = |
| 14423 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 14424 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14426 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14427 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14428 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14429 | hanging_alternate_protocol_socket.set_connect_data( |
| 14430 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14431 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14432 | &hanging_alternate_protocol_socket); |
| 14433 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14434 | // 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] | 14435 | StaticSocketDataProvider second_transaction(data_reads, |
| 14436 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14437 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14440 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14441 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14443 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14444 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14445 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14446 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14448 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14449 | |
| 14450 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14451 | ASSERT_TRUE(response); |
| 14452 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14453 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14454 | |
| 14455 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14456 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14457 | EXPECT_EQ("hello world", response_data); |
| 14458 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14459 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14460 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14462 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14464 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14465 | |
| 14466 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14467 | ASSERT_TRUE(response); |
| 14468 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14469 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14470 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14471 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14472 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14473 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14474 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14475 | } |
| 14476 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14477 | // Test that proxy is resolved using the origin url, |
| 14478 | // regardless of the alternative server. |
| 14479 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 14480 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 14481 | ProxyConfig proxy_config; |
| 14482 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 14483 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14484 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 14485 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14486 | |
| 14487 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14488 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14489 | &capturing_proxy_resolver); |
| 14490 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 14491 | RecordingTestNetLog net_log; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14492 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14493 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 14494 | std::make_unique<ConfiguredProxyResolutionService>( |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14495 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 14496 | &net_log, /*quick_check_enabled=*/true); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14497 | |
| 14498 | session_deps_.net_log = &net_log; |
| 14499 | |
| 14500 | // Configure alternative service with a hostname that is not bypassed by the |
| 14501 | // proxy. |
| 14502 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14503 | HttpServerProperties* http_server_properties = |
| 14504 | session->http_server_properties(); |
| 14505 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14506 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14507 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14508 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14509 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 14510 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14511 | |
| 14512 | // Non-alternative job should hang. |
| 14513 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14514 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14515 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 14516 | session_deps_.socket_factory->AddSocketDataProvider( |
| 14517 | &hanging_alternate_protocol_socket); |
| 14518 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14519 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14520 | |
| 14521 | HttpRequestInfo request; |
| 14522 | request.method = "GET"; |
| 14523 | request.url = GURL("https://www.example.org/"); |
| 14524 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14525 | request.traffic_annotation = |
| 14526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14527 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14528 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14529 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 14530 | |
| 14531 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 14532 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14533 | spdy::SpdySerializedFrame resp( |
| 14534 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14535 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14536 | MockRead spdy_reads[] = { |
| 14537 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 14538 | }; |
| 14539 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14540 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14541 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 14542 | |
| 14543 | TestCompletionCallback callback; |
| 14544 | |
| 14545 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14546 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14547 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14548 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 14549 | |
| 14550 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 14551 | ASSERT_TRUE(response); |
| 14552 | ASSERT_TRUE(response->headers); |
| 14553 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14554 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14555 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14556 | |
| 14557 | std::string response_data; |
| 14558 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 14559 | EXPECT_EQ("hello!", response_data); |
| 14560 | |
| 14561 | // Origin host bypasses proxy, no resolution should have happened. |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14562 | ASSERT_TRUE(capturing_proxy_resolver.lookup_info().empty()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 14563 | } |
| 14564 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14565 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14566 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 14567 | proxy_config.set_auto_detect(true); |
| 14568 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 14569 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 14570 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14571 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 14572 | std::make_unique<ConfiguredProxyResolutionService>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14573 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 14574 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 14575 | std::make_unique<CapturingProxyResolverFactory>( |
| 14576 | &capturing_proxy_resolver), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 14577 | nullptr, /*quick_check_enabled=*/true); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 14578 | RecordingTestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14579 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14580 | |
| 14581 | HttpRequestInfo request; |
| 14582 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14583 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14584 | request.traffic_annotation = |
| 14585 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14586 | |
| 14587 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14588 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14589 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14590 | MockRead("\r\n"), |
| 14591 | MockRead("hello world"), |
| 14592 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 14593 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14594 | }; |
| 14595 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14596 | StaticSocketDataProvider first_transaction(data_reads, |
| 14597 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14598 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14599 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14600 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14601 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14602 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14603 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14604 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14605 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14606 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14607 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14608 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14609 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14610 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14611 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14612 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14613 | }; |
| 14614 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 14615 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 14616 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14617 | spdy::SpdySerializedFrame resp( |
| 14618 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14619 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14620 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14621 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 14622 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14623 | }; |
| 14624 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14625 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14626 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14627 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14628 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14629 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14630 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 14631 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14632 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 14633 | &hanging_non_alternate_protocol_socket); |
| 14634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14635 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14638 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14639 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14640 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14641 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 14642 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14643 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 14644 | |
| 14645 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14646 | ASSERT_TRUE(response); |
| 14647 | ASSERT_TRUE(response->headers); |
| 14648 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 14649 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14650 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 14651 | |
| 14652 | std::string response_data; |
| 14653 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 14654 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14655 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14656 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14657 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14658 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14659 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14661 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14662 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 14663 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14664 | ASSERT_TRUE(response); |
| 14665 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14666 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14667 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14668 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14669 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14670 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14671 | EXPECT_EQ("hello!", response_data); |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14672 | ASSERT_EQ(2u, capturing_proxy_resolver.lookup_info().size()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14673 | EXPECT_EQ("https://www.example.org/", |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14674 | capturing_proxy_resolver.lookup_info()[0].url.spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14675 | EXPECT_EQ("https://www.example.org/", |
Matt Menke | 8045afd | 2019-11-14 20:31:19 | [diff] [blame] | 14676 | capturing_proxy_resolver.lookup_info()[1].url.spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14677 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14678 | LoadTimingInfo load_timing_info; |
| 14679 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 14680 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14681 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14682 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 14683 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14684 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 14685 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14686 | HttpRequestInfo request; |
| 14687 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14688 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14689 | request.traffic_annotation = |
| 14690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14691 | |
| 14692 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14693 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14694 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14695 | MockRead("\r\n"), |
| 14696 | MockRead("hello world"), |
| 14697 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14698 | }; |
| 14699 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14700 | StaticSocketDataProvider first_transaction(data_reads, |
| 14701 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14702 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14703 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14704 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14706 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14707 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14708 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14709 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 14710 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14711 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14712 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14713 | spdy::SpdySerializedFrame resp( |
| 14714 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14715 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14716 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14717 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14718 | }; |
| 14719 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14720 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14721 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14722 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 14723 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14724 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14726 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14727 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14728 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14729 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14730 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14732 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14733 | |
| 14734 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14735 | ASSERT_TRUE(response); |
| 14736 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14737 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14738 | |
| 14739 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14740 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14741 | EXPECT_EQ("hello world", response_data); |
| 14742 | |
| 14743 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14744 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14745 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 14746 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 14747 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 14748 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14749 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14750 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 14751 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14752 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14753 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14755 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14757 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14758 | |
| 14759 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14760 | ASSERT_TRUE(response); |
| 14761 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14762 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14763 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14764 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14765 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14766 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 14767 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 14768 | } |
| 14769 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14770 | // GenerateAuthToken is a mighty big test. |
| 14771 | // It tests all permutation of GenerateAuthToken behavior: |
| 14772 | // - Synchronous and Asynchronous completion. |
| 14773 | // - OK or error on completion. |
| 14774 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 14775 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 14776 | // - Non-authenticating and authenticating backend. |
| 14777 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 14778 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14779 | // problems generating an auth token for an authenticating proxy, we don't |
| 14780 | // need to test all permutations of the backend server). |
| 14781 | // |
| 14782 | // The test proceeds by going over each of the configuration cases, and |
| 14783 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 14784 | // specifies both the configuration for the test as well as the expectations |
| 14785 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14786 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14787 | static const char kServer[] = "http://www.example.com"; |
| 14788 | static const char kSecureServer[] = "https://www.example.com"; |
| 14789 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14790 | |
| 14791 | enum AuthTiming { |
| 14792 | AUTH_NONE, |
| 14793 | AUTH_SYNC, |
| 14794 | AUTH_ASYNC, |
| 14795 | }; |
| 14796 | |
| 14797 | const MockWrite kGet( |
| 14798 | "GET / HTTP/1.1\r\n" |
| 14799 | "Host: www.example.com\r\n" |
| 14800 | "Connection: keep-alive\r\n\r\n"); |
| 14801 | const MockWrite kGetProxy( |
| 14802 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14803 | "Host: www.example.com\r\n" |
| 14804 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 14805 | const MockWrite kGetAuth( |
| 14806 | "GET / HTTP/1.1\r\n" |
| 14807 | "Host: www.example.com\r\n" |
| 14808 | "Connection: keep-alive\r\n" |
| 14809 | "Authorization: auth_token\r\n\r\n"); |
| 14810 | const MockWrite kGetProxyAuth( |
| 14811 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14812 | "Host: www.example.com\r\n" |
| 14813 | "Proxy-Connection: keep-alive\r\n" |
| 14814 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 14815 | const MockWrite kGetAuthThroughProxy( |
| 14816 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14817 | "Host: www.example.com\r\n" |
| 14818 | "Proxy-Connection: keep-alive\r\n" |
| 14819 | "Authorization: auth_token\r\n\r\n"); |
| 14820 | const MockWrite kGetAuthWithProxyAuth( |
| 14821 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 14822 | "Host: www.example.com\r\n" |
| 14823 | "Proxy-Connection: keep-alive\r\n" |
| 14824 | "Proxy-Authorization: auth_token\r\n" |
| 14825 | "Authorization: auth_token\r\n\r\n"); |
| 14826 | const MockWrite kConnect( |
| 14827 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14828 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14829 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 14830 | const MockWrite kConnectProxyAuth( |
| 14831 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14832 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14833 | "Proxy-Connection: keep-alive\r\n" |
| 14834 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 14835 | |
| 14836 | const MockRead kSuccess( |
| 14837 | "HTTP/1.1 200 OK\r\n" |
| 14838 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14839 | "Content-Length: 3\r\n\r\n" |
| 14840 | "Yes"); |
| 14841 | const MockRead kFailure( |
| 14842 | "Should not be called."); |
| 14843 | const MockRead kServerChallenge( |
| 14844 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14845 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14846 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14847 | "Content-Length: 14\r\n\r\n" |
| 14848 | "Unauthorized\r\n"); |
| 14849 | const MockRead kProxyChallenge( |
| 14850 | "HTTP/1.1 407 Unauthorized\r\n" |
| 14851 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 14852 | "Proxy-Connection: close\r\n" |
| 14853 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14854 | "Content-Length: 14\r\n\r\n" |
| 14855 | "Unauthorized\r\n"); |
| 14856 | const MockRead kProxyConnected( |
| 14857 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 14858 | |
| 14859 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 14860 | // no constructors, but the C++ compiler on Windows warns about |
| 14861 | // unspecified data in compound literals. So, moved to using constructors, |
| 14862 | // and TestRound's created with the default constructor should not be used. |
| 14863 | struct TestRound { |
| 14864 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14865 | : expected_rv(ERR_UNEXPECTED), |
| 14866 | extra_write(nullptr), |
| 14867 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14868 | TestRound(const MockWrite& write_arg, |
| 14869 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14870 | int expected_rv_arg) |
| 14871 | : write(write_arg), |
| 14872 | read(read_arg), |
| 14873 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14874 | extra_write(nullptr), |
| 14875 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14876 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 14877 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 14878 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14879 | : write(write_arg), |
| 14880 | read(read_arg), |
| 14881 | expected_rv(expected_rv_arg), |
| 14882 | extra_write(extra_write_arg), |
| 14883 | extra_read(extra_read_arg) { |
| 14884 | } |
| 14885 | MockWrite write; |
| 14886 | MockRead read; |
| 14887 | int expected_rv; |
| 14888 | const MockWrite* extra_write; |
| 14889 | const MockRead* extra_read; |
| 14890 | }; |
| 14891 | |
| 14892 | static const int kNoSSL = 500; |
| 14893 | |
| 14894 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14895 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14896 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14897 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14898 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14899 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14900 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14901 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14902 | int num_auth_rounds; |
| 14903 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14904 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14905 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14906 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14907 | {__LINE__, |
| 14908 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14909 | AUTH_NONE, |
| 14910 | OK, |
| 14911 | kServer, |
| 14912 | AUTH_NONE, |
| 14913 | OK, |
| 14914 | 1, |
| 14915 | kNoSSL, |
| 14916 | {TestRound(kGet, kSuccess, OK)}}, |
| 14917 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14918 | {__LINE__, |
| 14919 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14920 | AUTH_NONE, |
| 14921 | OK, |
| 14922 | kServer, |
| 14923 | AUTH_SYNC, |
| 14924 | OK, |
| 14925 | 2, |
| 14926 | kNoSSL, |
| 14927 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14928 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14929 | {__LINE__, |
| 14930 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14931 | AUTH_NONE, |
| 14932 | OK, |
| 14933 | kServer, |
| 14934 | AUTH_SYNC, |
| 14935 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14936 | 3, |
| 14937 | kNoSSL, |
| 14938 | {TestRound(kGet, kServerChallenge, OK), |
| 14939 | TestRound(kGet, kServerChallenge, OK), |
| 14940 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14941 | {__LINE__, |
| 14942 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14943 | AUTH_NONE, |
| 14944 | OK, |
| 14945 | kServer, |
| 14946 | AUTH_SYNC, |
| 14947 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14948 | 2, |
| 14949 | kNoSSL, |
| 14950 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14951 | {__LINE__, |
| 14952 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14953 | AUTH_NONE, |
| 14954 | OK, |
| 14955 | kServer, |
| 14956 | AUTH_SYNC, |
| 14957 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 14958 | 2, |
| 14959 | kNoSSL, |
| 14960 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14961 | {__LINE__, |
| 14962 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14963 | AUTH_SYNC, |
| 14964 | ERR_FAILED, |
| 14965 | kServer, |
| 14966 | AUTH_NONE, |
| 14967 | OK, |
| 14968 | 2, |
| 14969 | kNoSSL, |
| 14970 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14971 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14972 | {__LINE__, |
| 14973 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14974 | AUTH_ASYNC, |
| 14975 | ERR_FAILED, |
| 14976 | kServer, |
| 14977 | AUTH_NONE, |
| 14978 | OK, |
| 14979 | 2, |
| 14980 | kNoSSL, |
| 14981 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14982 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14983 | {__LINE__, |
| 14984 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14985 | AUTH_NONE, |
| 14986 | OK, |
| 14987 | kServer, |
| 14988 | AUTH_SYNC, |
| 14989 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14990 | 2, |
| 14991 | kNoSSL, |
| 14992 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14993 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14994 | {__LINE__, |
| 14995 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14996 | AUTH_NONE, |
| 14997 | OK, |
| 14998 | kServer, |
| 14999 | AUTH_ASYNC, |
| 15000 | ERR_FAILED, |
| 15001 | 2, |
| 15002 | kNoSSL, |
| 15003 | {TestRound(kGet, kServerChallenge, OK), |
| 15004 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15005 | {__LINE__, |
| 15006 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15007 | AUTH_NONE, |
| 15008 | OK, |
| 15009 | kServer, |
| 15010 | AUTH_ASYNC, |
| 15011 | OK, |
| 15012 | 2, |
| 15013 | kNoSSL, |
| 15014 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15015 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15016 | {__LINE__, |
| 15017 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15018 | AUTH_NONE, |
| 15019 | OK, |
| 15020 | kServer, |
| 15021 | AUTH_ASYNC, |
| 15022 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15023 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15024 | kNoSSL, |
| 15025 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15026 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 15027 | TestRound(kGet, kServerChallenge, OK), |
| 15028 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15029 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15030 | {__LINE__, |
| 15031 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15032 | AUTH_NONE, |
| 15033 | OK, |
| 15034 | kServer, |
| 15035 | AUTH_NONE, |
| 15036 | OK, |
| 15037 | 1, |
| 15038 | kNoSSL, |
| 15039 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 15040 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15041 | {__LINE__, |
| 15042 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15043 | AUTH_NONE, |
| 15044 | OK, |
| 15045 | kServer, |
| 15046 | AUTH_SYNC, |
| 15047 | OK, |
| 15048 | 2, |
| 15049 | kNoSSL, |
| 15050 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15051 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15052 | {__LINE__, |
| 15053 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15054 | AUTH_NONE, |
| 15055 | OK, |
| 15056 | kServer, |
| 15057 | AUTH_SYNC, |
| 15058 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15059 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15060 | kNoSSL, |
| 15061 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15062 | TestRound(kGetProxy, kServerChallenge, OK), |
| 15063 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15064 | {__LINE__, |
| 15065 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15066 | AUTH_NONE, |
| 15067 | OK, |
| 15068 | kServer, |
| 15069 | AUTH_ASYNC, |
| 15070 | OK, |
| 15071 | 2, |
| 15072 | kNoSSL, |
| 15073 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15074 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15075 | {__LINE__, |
| 15076 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15077 | AUTH_NONE, |
| 15078 | OK, |
| 15079 | kServer, |
| 15080 | AUTH_ASYNC, |
| 15081 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15082 | 2, |
| 15083 | kNoSSL, |
| 15084 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15085 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15086 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15087 | {__LINE__, |
| 15088 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15089 | AUTH_SYNC, |
| 15090 | OK, |
| 15091 | kServer, |
| 15092 | AUTH_NONE, |
| 15093 | OK, |
| 15094 | 2, |
| 15095 | kNoSSL, |
| 15096 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15097 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15098 | {__LINE__, |
| 15099 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15100 | AUTH_SYNC, |
| 15101 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15102 | kServer, |
| 15103 | AUTH_NONE, |
| 15104 | OK, |
| 15105 | 2, |
| 15106 | kNoSSL, |
| 15107 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15108 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15109 | {__LINE__, |
| 15110 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15111 | AUTH_ASYNC, |
| 15112 | OK, |
| 15113 | kServer, |
| 15114 | AUTH_NONE, |
| 15115 | OK, |
| 15116 | 2, |
| 15117 | kNoSSL, |
| 15118 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15119 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15120 | {__LINE__, |
| 15121 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15122 | AUTH_ASYNC, |
| 15123 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15124 | kServer, |
| 15125 | AUTH_NONE, |
| 15126 | OK, |
| 15127 | 2, |
| 15128 | kNoSSL, |
| 15129 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15130 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15131 | {__LINE__, |
| 15132 | kProxy, |
| 15133 | AUTH_ASYNC, |
| 15134 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15135 | kServer, |
| 15136 | AUTH_NONE, |
| 15137 | OK, |
| 15138 | 3, |
| 15139 | kNoSSL, |
| 15140 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 15141 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 15142 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15143 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15144 | {__LINE__, |
| 15145 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15146 | AUTH_SYNC, |
| 15147 | OK, |
| 15148 | kServer, |
| 15149 | AUTH_SYNC, |
| 15150 | OK, |
| 15151 | 3, |
| 15152 | kNoSSL, |
| 15153 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15154 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 15155 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15156 | {__LINE__, |
| 15157 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15158 | AUTH_SYNC, |
| 15159 | OK, |
| 15160 | kServer, |
| 15161 | AUTH_SYNC, |
| 15162 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15163 | 3, |
| 15164 | kNoSSL, |
| 15165 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15166 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15167 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15168 | {__LINE__, |
| 15169 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15170 | AUTH_ASYNC, |
| 15171 | OK, |
| 15172 | kServer, |
| 15173 | AUTH_SYNC, |
| 15174 | OK, |
| 15175 | 3, |
| 15176 | kNoSSL, |
| 15177 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15178 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 15179 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15180 | {__LINE__, |
| 15181 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15182 | AUTH_ASYNC, |
| 15183 | OK, |
| 15184 | kServer, |
| 15185 | AUTH_SYNC, |
| 15186 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15187 | 3, |
| 15188 | kNoSSL, |
| 15189 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15190 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15191 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15192 | {__LINE__, |
| 15193 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15194 | AUTH_SYNC, |
| 15195 | OK, |
| 15196 | kServer, |
| 15197 | AUTH_ASYNC, |
| 15198 | OK, |
| 15199 | 3, |
| 15200 | kNoSSL, |
| 15201 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15202 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 15203 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15204 | {__LINE__, |
| 15205 | kProxy, |
| 15206 | AUTH_SYNC, |
| 15207 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15208 | kServer, |
| 15209 | AUTH_ASYNC, |
| 15210 | OK, |
| 15211 | 4, |
| 15212 | kNoSSL, |
| 15213 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 15214 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 15215 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 15216 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 15217 | {__LINE__, |
| 15218 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15219 | AUTH_SYNC, |
| 15220 | OK, |
| 15221 | kServer, |
| 15222 | AUTH_ASYNC, |
| 15223 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15224 | 3, |
| 15225 | kNoSSL, |
| 15226 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15227 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15228 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15229 | {__LINE__, |
| 15230 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15231 | AUTH_ASYNC, |
| 15232 | OK, |
| 15233 | kServer, |
| 15234 | AUTH_ASYNC, |
| 15235 | OK, |
| 15236 | 3, |
| 15237 | kNoSSL, |
| 15238 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15239 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 15240 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15241 | {__LINE__, |
| 15242 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15243 | AUTH_ASYNC, |
| 15244 | OK, |
| 15245 | kServer, |
| 15246 | AUTH_ASYNC, |
| 15247 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15248 | 3, |
| 15249 | kNoSSL, |
| 15250 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15251 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15252 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15253 | {__LINE__, |
| 15254 | kProxy, |
| 15255 | AUTH_ASYNC, |
| 15256 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15257 | kServer, |
| 15258 | AUTH_ASYNC, |
| 15259 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15260 | 4, |
| 15261 | kNoSSL, |
| 15262 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 15263 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 15264 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 15265 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15266 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15267 | {__LINE__, |
| 15268 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15269 | AUTH_NONE, |
| 15270 | OK, |
| 15271 | kSecureServer, |
| 15272 | AUTH_NONE, |
| 15273 | OK, |
| 15274 | 1, |
| 15275 | 0, |
| 15276 | {TestRound(kGet, kSuccess, OK)}}, |
| 15277 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15278 | {__LINE__, |
| 15279 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15280 | AUTH_NONE, |
| 15281 | OK, |
| 15282 | kSecureServer, |
| 15283 | AUTH_SYNC, |
| 15284 | OK, |
| 15285 | 2, |
| 15286 | 0, |
| 15287 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15288 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15289 | {__LINE__, |
| 15290 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15291 | AUTH_NONE, |
| 15292 | OK, |
| 15293 | kSecureServer, |
| 15294 | AUTH_SYNC, |
| 15295 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15296 | 2, |
| 15297 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15298 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15299 | {__LINE__, |
| 15300 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15301 | AUTH_NONE, |
| 15302 | OK, |
| 15303 | kSecureServer, |
| 15304 | AUTH_ASYNC, |
| 15305 | OK, |
| 15306 | 2, |
| 15307 | 0, |
| 15308 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15309 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15310 | {__LINE__, |
| 15311 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15312 | AUTH_NONE, |
| 15313 | OK, |
| 15314 | kSecureServer, |
| 15315 | AUTH_ASYNC, |
| 15316 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15317 | 2, |
| 15318 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15319 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15320 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15321 | {__LINE__, |
| 15322 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15323 | AUTH_NONE, |
| 15324 | OK, |
| 15325 | kSecureServer, |
| 15326 | AUTH_NONE, |
| 15327 | OK, |
| 15328 | 1, |
| 15329 | 0, |
| 15330 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 15331 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15332 | {__LINE__, |
| 15333 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15334 | AUTH_NONE, |
| 15335 | OK, |
| 15336 | kSecureServer, |
| 15337 | AUTH_SYNC, |
| 15338 | OK, |
| 15339 | 2, |
| 15340 | 0, |
| 15341 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15342 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15343 | {__LINE__, |
| 15344 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15345 | AUTH_NONE, |
| 15346 | OK, |
| 15347 | kSecureServer, |
| 15348 | AUTH_SYNC, |
| 15349 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15350 | 2, |
| 15351 | 0, |
| 15352 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15353 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15354 | {__LINE__, |
| 15355 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15356 | AUTH_NONE, |
| 15357 | OK, |
| 15358 | kSecureServer, |
| 15359 | AUTH_ASYNC, |
| 15360 | OK, |
| 15361 | 2, |
| 15362 | 0, |
| 15363 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15364 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15365 | {__LINE__, |
| 15366 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15367 | AUTH_NONE, |
| 15368 | OK, |
| 15369 | kSecureServer, |
| 15370 | AUTH_ASYNC, |
| 15371 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15372 | 2, |
| 15373 | 0, |
| 15374 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15375 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15376 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15377 | {__LINE__, |
| 15378 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15379 | AUTH_SYNC, |
| 15380 | OK, |
| 15381 | kSecureServer, |
| 15382 | AUTH_NONE, |
| 15383 | OK, |
| 15384 | 2, |
| 15385 | 1, |
| 15386 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15387 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15388 | {__LINE__, |
| 15389 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15390 | AUTH_SYNC, |
| 15391 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15392 | kSecureServer, |
| 15393 | AUTH_NONE, |
| 15394 | OK, |
| 15395 | 2, |
| 15396 | kNoSSL, |
| 15397 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15398 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15399 | {__LINE__, |
| 15400 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15401 | AUTH_SYNC, |
| 15402 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 15403 | kSecureServer, |
| 15404 | AUTH_NONE, |
| 15405 | OK, |
| 15406 | 2, |
| 15407 | kNoSSL, |
| 15408 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15409 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15410 | {__LINE__, |
| 15411 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15412 | AUTH_SYNC, |
| 15413 | ERR_UNEXPECTED, |
| 15414 | kSecureServer, |
| 15415 | AUTH_NONE, |
| 15416 | OK, |
| 15417 | 2, |
| 15418 | kNoSSL, |
| 15419 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15420 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15421 | {__LINE__, |
| 15422 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15423 | AUTH_ASYNC, |
| 15424 | OK, |
| 15425 | kSecureServer, |
| 15426 | AUTH_NONE, |
| 15427 | OK, |
| 15428 | 2, |
| 15429 | 1, |
| 15430 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15431 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15432 | {__LINE__, |
| 15433 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15434 | AUTH_ASYNC, |
| 15435 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15436 | kSecureServer, |
| 15437 | AUTH_NONE, |
| 15438 | OK, |
| 15439 | 2, |
| 15440 | kNoSSL, |
| 15441 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15442 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15443 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15444 | {__LINE__, |
| 15445 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15446 | AUTH_SYNC, |
| 15447 | OK, |
| 15448 | kSecureServer, |
| 15449 | AUTH_SYNC, |
| 15450 | OK, |
| 15451 | 3, |
| 15452 | 1, |
| 15453 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15454 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15455 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15456 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15457 | {__LINE__, |
| 15458 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15459 | AUTH_SYNC, |
| 15460 | OK, |
| 15461 | kSecureServer, |
| 15462 | AUTH_SYNC, |
| 15463 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15464 | 3, |
| 15465 | 1, |
| 15466 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15467 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15468 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15469 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15470 | {__LINE__, |
| 15471 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15472 | AUTH_ASYNC, |
| 15473 | OK, |
| 15474 | kSecureServer, |
| 15475 | AUTH_SYNC, |
| 15476 | OK, |
| 15477 | 3, |
| 15478 | 1, |
| 15479 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15480 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15481 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15482 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15483 | {__LINE__, |
| 15484 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15485 | AUTH_ASYNC, |
| 15486 | OK, |
| 15487 | kSecureServer, |
| 15488 | AUTH_SYNC, |
| 15489 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15490 | 3, |
| 15491 | 1, |
| 15492 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15493 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15494 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15495 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15496 | {__LINE__, |
| 15497 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15498 | AUTH_SYNC, |
| 15499 | OK, |
| 15500 | kSecureServer, |
| 15501 | AUTH_ASYNC, |
| 15502 | OK, |
| 15503 | 3, |
| 15504 | 1, |
| 15505 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15506 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15507 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15508 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15509 | {__LINE__, |
| 15510 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15511 | AUTH_SYNC, |
| 15512 | OK, |
| 15513 | kSecureServer, |
| 15514 | AUTH_ASYNC, |
| 15515 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15516 | 3, |
| 15517 | 1, |
| 15518 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15519 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15520 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15521 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15522 | {__LINE__, |
| 15523 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15524 | AUTH_ASYNC, |
| 15525 | OK, |
| 15526 | kSecureServer, |
| 15527 | AUTH_ASYNC, |
| 15528 | OK, |
| 15529 | 3, |
| 15530 | 1, |
| 15531 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15532 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15533 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15534 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15535 | {__LINE__, |
| 15536 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 15537 | AUTH_ASYNC, |
| 15538 | OK, |
| 15539 | kSecureServer, |
| 15540 | AUTH_ASYNC, |
| 15541 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15542 | 3, |
| 15543 | 1, |
| 15544 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15545 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15546 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15547 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15548 | {__LINE__, |
| 15549 | kProxy, |
| 15550 | AUTH_ASYNC, |
| 15551 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15552 | kSecureServer, |
| 15553 | AUTH_ASYNC, |
| 15554 | ERR_INVALID_AUTH_CREDENTIALS, |
| 15555 | 4, |
| 15556 | 2, |
| 15557 | {TestRound(kConnect, kProxyChallenge, OK), |
| 15558 | TestRound(kConnect, kProxyChallenge, OK), |
| 15559 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 15560 | &kServerChallenge), |
| 15561 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15562 | }; |
| 15563 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15564 | for (const auto& test_config : test_configs) { |
| 15565 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 15566 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15567 | HttpAuthHandlerMock::Factory* auth_factory( |
| 15568 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15569 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 15570 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 15571 | |
| 15572 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15573 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15574 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15575 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 15576 | std::string auth_challenge = "Mock realm=proxy"; |
| 15577 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 15578 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 15579 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15580 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
Matt Menke | 618134b | 2020-05-22 02:12:27 | [diff] [blame] | 15581 | empty_ssl_info, NetworkIsolationKey(), |
| 15582 | origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15583 | auth_handler->SetGenerateExpectation( |
| 15584 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15585 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15586 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 15587 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15588 | } |
| 15589 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 15590 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15591 | std::string auth_challenge = "Mock realm=server"; |
| 15592 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 15593 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 15594 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15595 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
Matt Menke | 618134b | 2020-05-22 02:12:27 | [diff] [blame] | 15596 | empty_ssl_info, NetworkIsolationKey(), |
| 15597 | origin, NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15598 | auth_handler->SetGenerateExpectation( |
| 15599 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15600 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15601 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15602 | |
| 15603 | // The second handler always succeeds. It should only be used where there |
| 15604 | // are multiple auth sessions for server auth in the same network |
| 15605 | // transaction using the same auth scheme. |
| 15606 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15607 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15608 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
Matt Menke | 618134b | 2020-05-22 02:12:27 | [diff] [blame] | 15609 | empty_ssl_info, NetworkIsolationKey(), |
| 15610 | origin, NetLogWithSource()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15611 | second_handler->SetGenerateExpectation(true, OK); |
| 15612 | auth_factory->AddMockHandler(second_handler.release(), |
| 15613 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15614 | } |
| 15615 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15616 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15617 | ConfiguredProxyResolutionService::CreateFixed( |
| 15618 | test_config.proxy_url, TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15619 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15620 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15621 | ConfiguredProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15622 | } |
| 15623 | |
| 15624 | HttpRequestInfo request; |
| 15625 | request.method = "GET"; |
| 15626 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15627 | request.traffic_annotation = |
| 15628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15629 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15630 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15631 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15632 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 15633 | |
| 15634 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 15635 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15636 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 15637 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15638 | const TestRound& read_write_round = test_config.rounds[round]; |
| 15639 | |
| 15640 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15641 | mock_reads.back().push_back(read_write_round.read); |
| 15642 | mock_writes.back().push_back(read_write_round.write); |
| 15643 | |
| 15644 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 15645 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15646 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15647 | mock_reads.push_back(std::vector<MockRead>()); |
| 15648 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15649 | } |
| 15650 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15651 | if (read_write_round.extra_read) { |
| 15652 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15653 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15654 | if (read_write_round.extra_write) { |
| 15655 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 15656 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15657 | |
| 15658 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15659 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15660 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15661 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15662 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15663 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15664 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15665 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15666 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15667 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15668 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 15669 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15670 | } |
| 15671 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 15672 | // Transaction must be created after DataProviders, so it's destroyed before |
| 15673 | // they are as well. |
| 15674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15675 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15676 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 15677 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 15678 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15679 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15680 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15681 | int rv; |
| 15682 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15683 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15684 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15685 | rv = trans.RestartWithAuth( |
| 15686 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15687 | } |
| 15688 | if (rv == ERR_IO_PENDING) |
| 15689 | rv = callback.WaitForResult(); |
| 15690 | |
| 15691 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15692 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15693 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 15694 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15695 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 15696 | continue; |
| 15697 | } |
| 15698 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15699 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15700 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15701 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 15702 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 15703 | } |
| 15704 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 15705 | } |
| 15706 | } |
| 15707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15708 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15709 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15710 | HttpAuthHandlerMock::Factory* auth_factory( |
| 15711 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15712 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15713 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 15714 | ConfiguredProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15715 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15716 | |
| 15717 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 15718 | auth_handler->set_connection_based(true); |
| 15719 | std::string auth_challenge = "Mock realm=server"; |
| 15720 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 15721 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 15722 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 15723 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15724 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
Matt Menke | 618134b | 2020-05-22 02:12:27 | [diff] [blame] | 15725 | empty_ssl_info, NetworkIsolationKey(), origin, |
| 15726 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 15727 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15728 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15729 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15730 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15731 | HttpRequestInfo request; |
| 15732 | request.method = "GET"; |
| 15733 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15734 | request.traffic_annotation = |
| 15735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15738 | |
| 15739 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 15740 | // to validate that the TCP socket is not released to the pool between |
| 15741 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15742 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 15743 | CommonConnectJobParams common_connect_job_params( |
| 15744 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 15745 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 15746 | 50, // Max sockets for pool |
| 15747 | 1, // Max sockets per group |
| 15748 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 15749 | ProxyServer::Direct(), false, // is_for_websockets |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 15750 | &common_connect_job_params); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15751 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 15752 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 15753 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 15754 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15756 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15757 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15758 | |
| 15759 | const MockWrite kGet( |
| 15760 | "GET / HTTP/1.1\r\n" |
| 15761 | "Host: www.example.com\r\n" |
| 15762 | "Connection: keep-alive\r\n\r\n"); |
| 15763 | const MockWrite kGetAuth( |
| 15764 | "GET / HTTP/1.1\r\n" |
| 15765 | "Host: www.example.com\r\n" |
| 15766 | "Connection: keep-alive\r\n" |
| 15767 | "Authorization: auth_token\r\n\r\n"); |
| 15768 | |
| 15769 | const MockRead kServerChallenge( |
| 15770 | "HTTP/1.1 401 Unauthorized\r\n" |
| 15771 | "WWW-Authenticate: Mock realm=server\r\n" |
| 15772 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15773 | "Content-Length: 14\r\n\r\n" |
| 15774 | "Unauthorized\r\n"); |
| 15775 | const MockRead kSuccess( |
| 15776 | "HTTP/1.1 200 OK\r\n" |
| 15777 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15778 | "Content-Length: 3\r\n\r\n" |
| 15779 | "Yes"); |
| 15780 | |
| 15781 | MockWrite writes[] = { |
| 15782 | // First round |
| 15783 | kGet, |
| 15784 | // Second round |
| 15785 | kGetAuth, |
| 15786 | // Third round |
| 15787 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15788 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15789 | kGetAuth, |
| 15790 | // Competing request |
| 15791 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15792 | }; |
| 15793 | MockRead reads[] = { |
| 15794 | // First round |
| 15795 | kServerChallenge, |
| 15796 | // Second round |
| 15797 | kServerChallenge, |
| 15798 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15799 | kServerChallenge, |
| 15800 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15801 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15802 | // Competing response |
| 15803 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15804 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15805 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15806 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15807 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 15808 | const ClientSocketPool::GroupId kSocketGroup( |
| 15809 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 15810 | PrivacyMode::PRIVACY_MODE_DISABLED, NetworkIsolationKey(), |
| 15811 | false /* disable_secure_dns */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15812 | |
| 15813 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15814 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15815 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15816 | if (rv == ERR_IO_PENDING) |
| 15817 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15818 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15819 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15820 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15821 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15822 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15823 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 15824 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15825 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15826 | // In between rounds, another request comes in for the same domain. |
| 15827 | // It should not be able to grab the TCP socket that trans has already |
| 15828 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15829 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15830 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15831 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 15832 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15834 | // callback_compete.WaitForResult at this point would stall forever, |
| 15835 | // since the HttpNetworkTransaction does not release the request back to |
| 15836 | // the pool until after authentication completes. |
| 15837 | |
| 15838 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15839 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15840 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15841 | if (rv == ERR_IO_PENDING) |
| 15842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15843 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15844 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15845 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15846 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15847 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15848 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 15849 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15850 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15851 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15852 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15853 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15854 | if (rv == ERR_IO_PENDING) |
| 15855 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15856 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15857 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15858 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15859 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15860 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15861 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 15862 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15863 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15864 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15865 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15866 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 15867 | if (rv == ERR_IO_PENDING) |
| 15868 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15869 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15870 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15871 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 15872 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15873 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15874 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 15875 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 15876 | // auth handler should transition to a DONE state in concert with the remote |
| 15877 | // server. But that's not something we can test here with a mock handler. |
| 15878 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 15879 | auth_handler->state()); |
| 15880 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15881 | // Read the body since the fourth round was successful. This will also |
| 15882 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 15883 | scoped_refptr<IOBufferWithSize> io_buf = |
| 15884 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15885 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15886 | if (rv == ERR_IO_PENDING) |
| 15887 | rv = callback.WaitForResult(); |
| 15888 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15889 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15890 | EXPECT_EQ(0, rv); |
| 15891 | // There are still 0 idle sockets, since the trans_compete transaction |
| 15892 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15893 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15894 | |
| 15895 | // The competing request can now finish. Wait for the headers and then |
| 15896 | // read the body. |
| 15897 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15898 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15899 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15900 | if (rv == ERR_IO_PENDING) |
| 15901 | rv = callback.WaitForResult(); |
| 15902 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15903 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 15904 | EXPECT_EQ(0, rv); |
| 15905 | |
| 15906 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 15907 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 15908 | } |
| 15909 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15910 | // This tests the case that a request is issued via http instead of spdy after |
| 15911 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15912 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15913 | HttpRequestInfo request; |
| 15914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15915 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15916 | request.traffic_annotation = |
| 15917 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15918 | |
| 15919 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15920 | MockWrite( |
| 15921 | "GET / HTTP/1.1\r\n" |
| 15922 | "Host: www.example.org\r\n" |
| 15923 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15924 | }; |
| 15925 | |
| 15926 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 15927 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 15928 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 15929 | MockRead("\r\n"), |
| 15930 | MockRead("hello world"), |
| 15931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15932 | }; |
| 15933 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15934 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15935 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15936 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15938 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15939 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15942 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15943 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15947 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15948 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15949 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15950 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15952 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15953 | ASSERT_TRUE(response); |
| 15954 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15955 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15956 | |
| 15957 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15958 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15959 | EXPECT_EQ("hello world", response_data); |
| 15960 | |
| 15961 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15962 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15963 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15964 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 15965 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 15966 | // immediate server closing of the socket. |
| 15967 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15968 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15969 | HttpRequestInfo request; |
| 15970 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15971 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15972 | request.traffic_annotation = |
| 15973 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15974 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15975 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15976 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15978 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15979 | spdy::SpdySerializedFrame req( |
| 15980 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15981 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15982 | |
| 15983 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15984 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15985 | }; |
| 15986 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15987 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15988 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15990 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15991 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15995 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15997 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15998 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 15999 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 16000 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 16001 | // it gets it. This is needed since the auth handler may get destroyed |
| 16002 | // before we get a chance to query it. |
| 16003 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 16004 | public: |
| 16005 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 16006 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16007 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 16008 | |
| 16009 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16010 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 16011 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 16012 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16013 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 16014 | *url_ = request->url; |
| 16015 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 16016 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 16017 | } |
| 16018 | |
| 16019 | private: |
| 16020 | GURL* url_; |
| 16021 | }; |
| 16022 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16023 | // Test that if we cancel the transaction as the connection is completing, that |
| 16024 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16025 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16026 | // Setup everything about the connection to complete synchronously, so that |
| 16027 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 16028 | // for is the callback from the HttpStreamRequest. |
| 16029 | // Then cancel the transaction. |
| 16030 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 16031 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16032 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16033 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 16034 | MockRead(SYNCHRONOUS, "hello world"), |
| 16035 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16036 | }; |
| 16037 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16038 | HttpRequestInfo request; |
| 16039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16040 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16041 | request.traffic_annotation = |
| 16042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16043 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16045 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16046 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16047 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16048 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16049 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16052 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16053 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16054 | RecordingBoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16055 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 16057 | trans.reset(); // Cancel the transaction here. |
| 16058 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16059 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 16060 | } |
| 16061 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16062 | // Test that if a transaction is cancelled after receiving the headers, the |
| 16063 | // stream is drained properly and added back to the socket pool. The main |
| 16064 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 16065 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 16066 | // deleted. |
| 16067 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16068 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16069 | MockRead data_reads[] = { |
| 16070 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 16071 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 16072 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 16073 | MockRead(ASYNC, "1"), |
| 16074 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 16075 | // HttpNetworkTransaction has been deleted. |
| 16076 | MockRead(ASYNC, "2"), |
| 16077 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 16078 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16079 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16080 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16081 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16082 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16083 | |
| 16084 | { |
| 16085 | HttpRequestInfo request; |
| 16086 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16087 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16088 | request.traffic_annotation = |
| 16089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16090 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16092 | TestCompletionCallback callback; |
| 16093 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16094 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16096 | callback.WaitForResult(); |
| 16097 | |
| 16098 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16099 | ASSERT_TRUE(response); |
| 16100 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16101 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16102 | |
| 16103 | // The transaction and HttpRequestInfo are deleted. |
| 16104 | } |
| 16105 | |
| 16106 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16107 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16108 | |
| 16109 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16110 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 16111 | } |
| 16112 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16113 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16114 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16115 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16116 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16117 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16118 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16119 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16121 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16122 | HttpRequestInfo request; |
| 16123 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16124 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16125 | request.traffic_annotation = |
| 16126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16127 | |
| 16128 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16129 | MockWrite( |
| 16130 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 16131 | "Host: www.example.org\r\n" |
| 16132 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16133 | }; |
| 16134 | |
| 16135 | MockRead data_reads1[] = { |
| 16136 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16137 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16138 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16139 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16140 | }; |
| 16141 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16142 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16143 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16145 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16147 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 16148 | ConnectedHandler connected_handler; |
| 16149 | trans.SetConnectedCallback(connected_handler.Callback()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 16150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16151 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16152 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16153 | |
| 16154 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16155 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16157 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16158 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16159 | |
| 16160 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 16161 | EXPECT_EQ(200, response->headers->response_code()); |
| 16162 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 16163 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 16164 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 16165 | HostPortPair::FromString("myproxy:70")), |
| 16166 | response->proxy_server); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16167 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 16168 | |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 16169 | TransportInfo expected_transport; |
| 16170 | expected_transport.type = TransportType::kProxied; |
| 16171 | expected_transport.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 70); |
| 16172 | EXPECT_THAT(connected_handler.transports(), ElementsAre(expected_transport)); |
| 16173 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 16174 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16175 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 16176 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 16177 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16178 | } |
| 16179 | |
| 16180 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16181 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16182 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16183 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16184 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16185 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16186 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16188 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16189 | HttpRequestInfo request; |
| 16190 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16191 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16192 | request.traffic_annotation = |
| 16193 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16194 | |
| 16195 | // Since we have proxy, should try to establish tunnel. |
| 16196 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16197 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16198 | "Host: www.example.org:443\r\n" |
| 16199 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16200 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16201 | MockWrite("GET / HTTP/1.1\r\n" |
| 16202 | "Host: www.example.org\r\n" |
| 16203 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16204 | }; |
| 16205 | |
| 16206 | MockRead data_reads1[] = { |
| 16207 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16208 | |
| 16209 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16210 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16211 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16212 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16213 | }; |
| 16214 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16215 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16216 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16217 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16220 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16222 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 16223 | ConnectedHandler connected_handler; |
| 16224 | trans.SetConnectedCallback(connected_handler.Callback()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 16225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16226 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16228 | |
| 16229 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16230 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16231 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16232 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16233 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 16234 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16235 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 16236 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16237 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 16238 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16240 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16241 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16242 | |
| 16243 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 16244 | EXPECT_EQ(200, response->headers->response_code()); |
| 16245 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 16246 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 16247 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 16248 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 16249 | HostPortPair::FromString("myproxy:70")), |
| 16250 | response->proxy_server); |
Titouan Rigoudy | ba507a88 | 2020-07-31 12:15:15 | [diff] [blame] | 16251 | |
| 16252 | TransportInfo expected_transport; |
| 16253 | expected_transport.type = TransportType::kProxied; |
| 16254 | expected_transport.endpoint = IPEndPoint(IPAddress::IPv4Localhost(), 70); |
| 16255 | EXPECT_THAT(connected_handler.transports(), ElementsAre(expected_transport)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 16256 | |
| 16257 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16258 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 16259 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 16260 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16261 | } |
| 16262 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16263 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 16264 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16265 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16266 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16267 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16268 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16269 | RecordingBoundTestNetLog log; |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16270 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16272 | |
| 16273 | HttpRequestInfo request; |
| 16274 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 16275 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16276 | request.traffic_annotation = |
| 16277 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16278 | |
| 16279 | // Since we have proxy, should try to establish tunnel. |
| 16280 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 16281 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 16282 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16283 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 16284 | |
| 16285 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 16286 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16287 | "Connection: keep-alive\r\n\r\n"), |
| 16288 | }; |
| 16289 | |
| 16290 | MockRead data_reads1[] = { |
| 16291 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16292 | |
| 16293 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16294 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16295 | MockRead("Content-Length: 100\r\n\r\n"), |
| 16296 | MockRead(SYNCHRONOUS, OK), |
| 16297 | }; |
| 16298 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16299 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16300 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16301 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16303 | |
| 16304 | TestCompletionCallback callback1; |
| 16305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16308 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16309 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16310 | |
| 16311 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16312 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16313 | auto entries = log.GetEntries(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16314 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16315 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 16316 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16317 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16318 | entries, pos, |
| 16319 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 16320 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16322 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16323 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16324 | |
| 16325 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 16326 | EXPECT_EQ(200, response->headers->response_code()); |
| 16327 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 16328 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 16329 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 16330 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 16331 | HostPortPair::FromString("myproxy:70")), |
| 16332 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16333 | |
| 16334 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16335 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16336 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 16337 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16338 | } |
| 16339 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16340 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 16341 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16342 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16343 | session_deps_.proxy_resolution_service = |
| 16344 | ConfiguredProxyResolutionService::CreateFixed( |
| 16345 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16346 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16347 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16349 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16350 | HttpRequestInfo request; |
| 16351 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16352 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16353 | request.traffic_annotation = |
| 16354 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16355 | |
| 16356 | // Since we have proxy, should try to establish tunnel. |
| 16357 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16358 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16359 | "Host: www.example.org:443\r\n" |
| 16360 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16361 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16362 | MockWrite("GET / HTTP/1.1\r\n" |
| 16363 | "Host: www.example.org\r\n" |
| 16364 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16365 | }; |
| 16366 | |
| 16367 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16368 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16369 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16370 | }; |
| 16371 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16372 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16373 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16374 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16377 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16378 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 16380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16381 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16383 | |
| 16384 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16385 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16386 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16387 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16388 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 16389 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16390 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 16391 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 16392 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 16393 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 16394 | } |
| 16395 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16396 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16397 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16398 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16399 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16400 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16401 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16402 | spdy::SpdySerializedFrame resp( |
| 16403 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16404 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16405 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16406 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16407 | }; |
| 16408 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16409 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16410 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16411 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16412 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16413 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16415 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16416 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16417 | |
| 16418 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16419 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 16420 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16421 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 16422 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 16423 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 16424 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 16425 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16426 | |
| 16427 | HttpRequestInfo request; |
| 16428 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16429 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16430 | request.traffic_annotation = |
| 16431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16433 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16434 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16435 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16438 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 16439 | } |
| 16440 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16441 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16442 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16443 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16444 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16445 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16446 | request_info.url = GURL("https://www.example.com/"); |
| 16447 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16448 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16449 | request_info.traffic_annotation = |
| 16450 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16451 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16452 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16453 | MockWrite data_writes[] = { |
| 16454 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16455 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16456 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16457 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16458 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16459 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16460 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16461 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16463 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16464 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16465 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16466 | rv = callback.WaitForResult(); |
| 16467 | ASSERT_EQ(error, rv); |
| 16468 | } |
| 16469 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16470 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16471 | // Just check a grab bag of cert errors. |
| 16472 | static const int kErrors[] = { |
| 16473 | ERR_CERT_COMMON_NAME_INVALID, |
| 16474 | ERR_CERT_AUTHORITY_INVALID, |
| 16475 | ERR_CERT_DATE_INVALID, |
| 16476 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 16477 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 16478 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 16479 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 16480 | } |
| 16481 | } |
| 16482 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16483 | // Ensure that a client certificate is removed from the SSL client auth |
| 16484 | // cache when: |
| 16485 | // 1) No proxy is involved. |
| 16486 | // 2) TLS False Start is disabled. |
| 16487 | // 3) The initial TLS handshake requests a client certificate. |
| 16488 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16489 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16490 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16491 | request_info.url = GURL("https://www.example.com/"); |
| 16492 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16493 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16494 | request_info.traffic_annotation = |
| 16495 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16496 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 16497 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 16498 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16499 | |
| 16500 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 16501 | // CertificateRequest is received for the first time, the handshake will |
| 16502 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16503 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16504 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16505 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16506 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16507 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16508 | |
| 16509 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 16510 | // False Start is not being used, the result of the SSL handshake will be |
| 16511 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 16512 | // matches the result of a server sending a handshake_failure alert, |
| 16513 | // rather than a Finished message, because it requires a client |
| 16514 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16515 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16516 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16518 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16519 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16520 | |
| 16521 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 16522 | // connection to a server fails during an SSL handshake, |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16523 | // HttpNetworkTransaction will attempt to fallback with legacy cryptography |
| 16524 | // enabled on some errors. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16525 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 16526 | // requiring a client certificate, this fallback handshake should also |
| 16527 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16528 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16529 | ssl_data3.expected_disable_legacy_crypto = false; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16530 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16532 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16533 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16534 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16536 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16537 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16538 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16539 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16540 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16541 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16542 | |
| 16543 | // Complete the SSL handshake, which should abort due to requiring a |
| 16544 | // client certificate. |
| 16545 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16546 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16547 | |
| 16548 | // Indicate that no certificate should be supplied. From the perspective |
| 16549 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 16550 | // certificate, so this is the same as supply a |
| 16551 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16552 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16553 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16554 | |
| 16555 | // Ensure the certificate was added to the client auth cache before |
| 16556 | // allowing the connection to continue restarting. |
| 16557 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16558 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16559 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16560 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16561 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16562 | |
| 16563 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16564 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 16565 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16566 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16567 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16568 | |
| 16569 | // Ensure that the client certificate is removed from the cache on a |
| 16570 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16571 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16572 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16573 | } |
| 16574 | |
| 16575 | // Ensure that a client certificate is removed from the SSL client auth |
| 16576 | // cache when: |
| 16577 | // 1) No proxy is involved. |
| 16578 | // 2) TLS False Start is enabled. |
| 16579 | // 3) The initial TLS handshake requests a client certificate. |
| 16580 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16581 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16582 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16583 | request_info.url = GURL("https://www.example.com/"); |
| 16584 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16585 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16586 | request_info.traffic_annotation = |
| 16587 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 16588 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 16589 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 16590 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16591 | |
| 16592 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 16593 | // return successfully after reading up to the peer's Certificate message. |
| 16594 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 16595 | // enqueue application data to be sent in the same packet as the |
| 16596 | // ChangeCipherSpec and Finished messages. |
| 16597 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 16598 | // called, which expects to process the peer's ChangeCipherSpec and |
| 16599 | // Finished messages. If there was an error negotiating with the peer, |
| 16600 | // such as due to the peer requiring a client certificate when none was |
| 16601 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 16602 | // called. |
| 16603 | |
| 16604 | // Like the non-False Start case, when a client certificate is requested by |
| 16605 | // the peer, the handshake is aborted during the Connect() call. |
| 16606 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16607 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16608 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16610 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16611 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16612 | |
| 16613 | // When a client certificate is supplied, Connect() will not be aborted |
| 16614 | // when the peer requests the certificate. Instead, the handshake will |
| 16615 | // artificially succeed, allowing the caller to write the HTTP request to |
| 16616 | // the socket. The handshake messages are not processed until Read() is |
| 16617 | // called, which then detects that the handshake was aborted, due to the |
| 16618 | // peer sending a handshake_failure because it requires a client |
| 16619 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16620 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16621 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16623 | MockRead data2_reads[] = { |
| 16624 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16625 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16626 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16627 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16628 | |
| 16629 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16630 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 16631 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16632 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16633 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16635 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16636 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16637 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16638 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 16639 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16640 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16641 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16642 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16643 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16644 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16645 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 16646 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16647 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 16648 | ssl_data5.cert_request_info = cert_request.get(); |
| 16649 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16650 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 16651 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 16652 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16654 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16655 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16656 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 16657 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16658 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16659 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16660 | |
| 16661 | // Complete the SSL handshake, which should abort due to requiring a |
| 16662 | // client certificate. |
| 16663 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16664 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16665 | |
| 16666 | // Indicate that no certificate should be supplied. From the perspective |
| 16667 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 16668 | // certificate, so this is the same as supply a |
| 16669 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16670 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16671 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16672 | |
| 16673 | // Ensure the certificate was added to the client auth cache before |
| 16674 | // allowing the connection to continue restarting. |
| 16675 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16676 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16677 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16678 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16679 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16680 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16681 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 16682 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 16683 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16684 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16685 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16686 | |
| 16687 | // Ensure that the client certificate is removed from the cache on a |
| 16688 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16689 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 16690 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 16691 | } |
| 16692 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16693 | // Ensure that a client certificate is removed from the SSL client auth |
| 16694 | // cache when: |
| 16695 | // 1) An HTTPS proxy is involved. |
| 16696 | // 3) The HTTPS proxy requests a client certificate. |
| 16697 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 16698 | // proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16699 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 16700 | session_deps_.proxy_resolution_service = |
| 16701 | ConfiguredProxyResolutionService::CreateFixed( |
| 16702 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 16703 | RecordingBoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16704 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16705 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16706 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 16707 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16708 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16709 | // Repeat the test for connecting to an HTTPS endpoint, then for connecting to |
| 16710 | // an HTTP endpoint. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16711 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16712 | requests[0].url = GURL("https://www.example.com/"); |
| 16713 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16714 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16715 | requests[0].traffic_annotation = |
| 16716 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16717 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16718 | // HTTPS requests are tunneled. |
| 16719 | MockWrite https_writes[] = { |
| 16720 | MockWrite("CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 16721 | "Host: www.example.com:443\r\n" |
| 16722 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 16723 | }; |
| 16724 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16725 | requests[1].url = GURL("http://www.example.com/"); |
| 16726 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16727 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16728 | requests[1].traffic_annotation = |
| 16729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16730 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16731 | // HTTP requests are not. |
| 16732 | MockWrite http_writes[] = { |
| 16733 | MockWrite("GET http://www.example.com/ HTTP/1.1\r\n" |
| 16734 | "Host: www.example.com\r\n" |
| 16735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 16736 | }; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16737 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16738 | // When the server rejects the client certificate, it will close the |
| 16739 | // connection. In TLS 1.2, this is signaled out of Connect(). In TLS 1.3 (or |
| 16740 | // TLS 1.2 with False Start), the error is returned out of the first Read(). |
| 16741 | for (bool reject_in_connect : {true, false}) { |
| 16742 | SCOPED_TRACE(reject_in_connect); |
| 16743 | // Client certificate errors are typically signaled with |
| 16744 | // ERR_BAD_SSL_CLIENT_AUTH_CERT, but sometimes the server gives an arbitrary |
| 16745 | // protocol error. |
| 16746 | for (Error reject_error : |
| 16747 | {ERR_SSL_PROTOCOL_ERROR, ERR_BAD_SSL_CLIENT_AUTH_CERT}) { |
| 16748 | SCOPED_TRACE(reject_error); |
| 16749 | // Tunneled and non-tunneled requests are handled differently. Test both. |
| 16750 | for (const HttpRequestInfo& request : requests) { |
| 16751 | SCOPED_TRACE(request.url); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16752 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16753 | session_deps_.socket_factory = |
| 16754 | std::make_unique<MockClientSocketFactory>(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16755 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16756 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16757 | // [ssl_]data[1-3]. |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16758 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 16759 | ssl_data1.cert_request_info = cert_request.get(); |
| 16760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 16761 | StaticSocketDataProvider data1; |
| 16762 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16763 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16764 | base::Optional<SSLSocketDataProvider> ssl_data2; |
| 16765 | base::Optional<StaticSocketDataProvider> data2; |
| 16766 | MockRead error_in_read[] = {MockRead(ASYNC, reject_error)}; |
| 16767 | if (reject_in_connect) { |
| 16768 | ssl_data2.emplace(ASYNC, reject_error); |
| 16769 | // There are no reads or writes. |
| 16770 | data2.emplace(); |
| 16771 | } else { |
| 16772 | ssl_data2.emplace(ASYNC, OK); |
| 16773 | // We will get one Write() in before observing the error in Read(). |
| 16774 | if (request.url.SchemeIsCryptographic()) { |
| 16775 | data2.emplace(error_in_read, https_writes); |
| 16776 | } else { |
| 16777 | data2.emplace(error_in_read, http_writes); |
| 16778 | } |
| 16779 | } |
| 16780 | ssl_data2->cert_request_info = cert_request.get(); |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16781 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 16782 | &ssl_data2.value()); |
| 16783 | session_deps_.socket_factory->AddSocketDataProvider(&data2.value()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16784 | |
David Benjamin | 07a07d65 | 2020-02-26 22:26:59 | [diff] [blame] | 16785 | // If the handshake returns ERR_SSL_PROTOCOL_ERROR, we attempt to |
| 16786 | // connect twice. |
| 16787 | base::Optional<SSLSocketDataProvider> ssl_data3; |
| 16788 | base::Optional<StaticSocketDataProvider> data3; |
| 16789 | if (reject_in_connect && reject_error == ERR_SSL_PROTOCOL_ERROR) { |
| 16790 | ssl_data3.emplace(ASYNC, reject_error); |
| 16791 | data3.emplace(); // There are no reads or writes. |
| 16792 | ssl_data3->cert_request_info = cert_request.get(); |
| 16793 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 16794 | &ssl_data3.value()); |
| 16795 | session_deps_.socket_factory->AddSocketDataProvider(&data3.value()); |
| 16796 | } |
| 16797 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16798 | std::unique_ptr<HttpNetworkSession> session = |
| 16799 | CreateSession(&session_deps_); |
| 16800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16801 | |
| 16802 | // Begin the SSL handshake with the proxy. |
| 16803 | TestCompletionCallback callback; |
| 16804 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16805 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16806 | |
| 16807 | // Complete the SSL handshake, which should abort due to requiring a |
| 16808 | // client certificate. |
| 16809 | rv = callback.WaitForResult(); |
| 16810 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 16811 | |
| 16812 | // Indicate that no certificate should be supplied. From the |
| 16813 | // perspective of SSLClientCertCache, NULL is just as meaningful as a |
| 16814 | // real certificate, so this is the same as supply a |
| 16815 | // legitimate-but-unacceptable certificate. |
| 16816 | rv = |
| 16817 | trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
| 16818 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16819 | |
| 16820 | // Ensure the certificate was added to the client auth cache before |
| 16821 | // allowing the connection to continue restarting. |
| 16822 | scoped_refptr<X509Certificate> client_cert; |
| 16823 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16824 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16825 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 16826 | ASSERT_FALSE(client_cert); |
| 16827 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 16828 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16829 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16830 | HostPortPair("www.example.com", 443), &client_cert, |
| 16831 | &client_private_key)); |
| 16832 | |
| 16833 | // Restart the handshake. This will consume ssl_data2. The result code |
| 16834 | // is checked against what ssl_data2 should return. |
| 16835 | rv = callback.WaitForResult(); |
| 16836 | ASSERT_THAT(rv, AnyOf(IsError(ERR_PROXY_CONNECTION_FAILED), |
| 16837 | IsError(reject_error))); |
| 16838 | |
| 16839 | // Now that the new handshake has failed, ensure that the client |
| 16840 | // certificate was removed from the client auth cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16841 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16842 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16843 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 16844 | HostPortPair("www.example.com", 443), &client_cert, |
| 16845 | &client_private_key)); |
| 16846 | } |
| 16847 | } |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 16848 | } |
| 16849 | } |
| 16850 | |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 16851 | // Test that HttpNetworkTransaction correctly handles (mocked) certificate |
| 16852 | // requests during a TLS renegotiation. |
| 16853 | TEST_F(HttpNetworkTransactionTest, CertificateRequestInRenego) { |
| 16854 | HttpRequestInfo request_info; |
| 16855 | request_info.url = GURL("https://www.example.com/"); |
| 16856 | request_info.method = "GET"; |
| 16857 | request_info.load_flags = LOAD_NORMAL; |
| 16858 | request_info.traffic_annotation = |
| 16859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16860 | |
| 16861 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 16862 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
| 16863 | |
| 16864 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 16865 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 16866 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 16867 | ASSERT_TRUE(identity); |
| 16868 | |
| 16869 | // The first connection's handshake succeeds, but we get |
| 16870 | // ERR_SSL_CLIENT_AUTH_CERT_NEEDED instead of an HTTP response. |
| 16871 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 16872 | ssl_data1.cert_request_info = cert_request.get(); |
| 16873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 16874 | MockWrite data1_writes[] = { |
| 16875 | MockWrite("GET / HTTP/1.1\r\n" |
| 16876 | "Host: www.example.com\r\n" |
| 16877 | "Connection: keep-alive\r\n\r\n"), |
| 16878 | }; |
| 16879 | MockRead data1_reads[] = { |
| 16880 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED), |
| 16881 | }; |
| 16882 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 16883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16884 | |
| 16885 | // After supplying with certificate, we restart the request from the top, |
| 16886 | // which succeeds this time. |
| 16887 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 16888 | ssl_data2.expected_send_client_cert = true; |
| 16889 | ssl_data2.expected_client_cert = identity->certificate(); |
| 16890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 16891 | MockWrite data2_writes[] = { |
| 16892 | MockWrite("GET / HTTP/1.1\r\n" |
| 16893 | "Host: www.example.com\r\n" |
| 16894 | "Connection: keep-alive\r\n\r\n"), |
| 16895 | }; |
| 16896 | MockRead data2_reads[] = { |
| 16897 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16898 | "Content-Length: 0\r\n\r\n"), |
| 16899 | }; |
| 16900 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 16901 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16902 | |
| 16903 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 16904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16905 | |
| 16906 | TestCompletionCallback callback; |
| 16907 | int rv = callback.GetResult( |
| 16908 | trans.Start(&request_info, callback.callback(), NetLogWithSource())); |
| 16909 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 16910 | |
| 16911 | rv = trans.RestartWithCertificate(identity->certificate(), |
| 16912 | identity->ssl_private_key(), |
| 16913 | callback.callback()); |
| 16914 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16915 | |
| 16916 | // Ensure the certificate was added to the client auth cache |
| 16917 | // allowing the connection to continue restarting. |
| 16918 | scoped_refptr<X509Certificate> client_cert; |
| 16919 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16920 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 16921 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 16922 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 16923 | |
| 16924 | // Complete the handshake. The request now succeeds. |
| 16925 | rv = callback.WaitForResult(); |
| 16926 | ASSERT_THAT(rv, IsError(OK)); |
| 16927 | EXPECT_EQ(200, trans.GetResponseInfo()->headers->response_code()); |
| 16928 | |
| 16929 | // The client certificate remains in the cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 16930 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 16931 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 16932 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 16933 | } |
| 16934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16935 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16936 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16937 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16939 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 16940 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16941 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16942 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16943 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16944 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16945 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16946 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16947 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16948 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16949 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16950 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16951 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16952 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16953 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16954 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16955 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16956 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16957 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16958 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16959 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16960 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16961 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16962 | }; |
| 16963 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16964 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16965 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16966 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16967 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16968 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 16969 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16970 | HttpRequestInfo request1; |
| 16971 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16972 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16973 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16974 | request1.traffic_annotation = |
| 16975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16976 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16977 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16978 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16980 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16981 | |
| 16982 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16983 | ASSERT_TRUE(response); |
| 16984 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16985 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16986 | |
| 16987 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16988 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16989 | EXPECT_EQ("hello!", response_data); |
| 16990 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16991 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16992 | rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 16993 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 16994 | base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16996 | |
| 16997 | HttpRequestInfo request2; |
| 16998 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16999 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17000 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17001 | request2.traffic_annotation = |
| 17002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17003 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17005 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17007 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17008 | |
| 17009 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17010 | ASSERT_TRUE(response); |
| 17011 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17012 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17013 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17014 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17015 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17016 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17017 | } |
| 17018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17019 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17020 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17021 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17023 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 17024 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17025 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17026 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17027 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17028 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17029 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 17030 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17031 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17032 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17033 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17034 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17035 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17036 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17037 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17038 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17039 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17040 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17041 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17042 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17043 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 17044 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17045 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17046 | }; |
| 17047 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 17048 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17049 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17050 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17051 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17052 | |
| 17053 | TestCompletionCallback callback; |
| 17054 | HttpRequestInfo request1; |
| 17055 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17056 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17057 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17058 | request1.traffic_annotation = |
| 17059 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17060 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17061 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17062 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17064 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17065 | |
| 17066 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17067 | ASSERT_TRUE(response); |
| 17068 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17069 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17070 | |
| 17071 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17072 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17073 | EXPECT_EQ("hello!", response_data); |
| 17074 | |
| 17075 | HttpRequestInfo request2; |
| 17076 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 17077 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17078 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17079 | request2.traffic_annotation = |
| 17080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17081 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17082 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17083 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17085 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17086 | |
| 17087 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17088 | ASSERT_TRUE(response); |
| 17089 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17090 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17091 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17092 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17093 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17094 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17095 | } |
| 17096 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17097 | // Regression test for https://crbug.com/546991. |
| 17098 | // The server might not be able to serve an IP pooled request, and might send a |
| 17099 | // 421 Misdirected Request response status to indicate this. |
| 17100 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 17101 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 17102 | // Two hosts resolve to the same IP address. |
| 17103 | const std::string ip_addr = "1.2.3.4"; |
| 17104 | IPAddress ip; |
| 17105 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 17106 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 17107 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17108 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17109 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 17110 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 17111 | |
| 17112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17113 | |
| 17114 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17115 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17116 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 17117 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17118 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17119 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17120 | spdy::SpdySerializedFrame rst( |
| 17121 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17122 | MockWrite writes1[] = { |
| 17123 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 17124 | CreateMockWrite(rst, 6), |
| 17125 | }; |
| 17126 | |
| 17127 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17128 | spdy::SpdySerializedFrame resp1( |
| 17129 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 17130 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 17131 | spdy::Http2HeaderBlock response_headers; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17132 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 17133 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17134 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 17135 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 17136 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 17137 | |
| 17138 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17139 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17140 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 17141 | |
| 17142 | AddSSLSocketData(); |
| 17143 | |
| 17144 | // Retry the second request on a second connection. |
| 17145 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17146 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17147 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 17148 | MockWrite writes2[] = { |
| 17149 | CreateMockWrite(req3, 0), |
| 17150 | }; |
| 17151 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17152 | spdy::SpdySerializedFrame resp3( |
| 17153 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 17154 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17155 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 17156 | MockRead(ASYNC, 0, 3)}; |
| 17157 | |
| 17158 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17159 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17160 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 17161 | |
| 17162 | AddSSLSocketData(); |
| 17163 | |
| 17164 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17165 | int rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 17166 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 17167 | base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17168 | EXPECT_THAT(rv, IsOk()); |
| 17169 | |
| 17170 | HttpRequestInfo request1; |
| 17171 | request1.method = "GET"; |
| 17172 | request1.url = GURL("https://www.example.org/"); |
| 17173 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17174 | request1.traffic_annotation = |
| 17175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17176 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 17177 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17178 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17179 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 17180 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17181 | rv = callback.WaitForResult(); |
| 17182 | EXPECT_THAT(rv, IsOk()); |
| 17183 | |
| 17184 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 17185 | ASSERT_TRUE(response); |
| 17186 | ASSERT_TRUE(response->headers); |
| 17187 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 17188 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 17189 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 17190 | std::string response_data; |
| 17191 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 17192 | EXPECT_EQ("hello!", response_data); |
| 17193 | |
| 17194 | HttpRequestInfo request2; |
| 17195 | request2.method = "GET"; |
| 17196 | request2.url = GURL("https://mail.example.org/"); |
| 17197 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17198 | request2.traffic_annotation = |
| 17199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17200 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 17201 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 17202 | RecordingBoundTestNetLog log; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17203 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 17204 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17205 | rv = callback.WaitForResult(); |
| 17206 | EXPECT_THAT(rv, IsOk()); |
| 17207 | |
| 17208 | response = trans2.GetResponseInfo(); |
| 17209 | ASSERT_TRUE(response); |
| 17210 | ASSERT_TRUE(response->headers); |
| 17211 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 17212 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 17213 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 17214 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 17215 | EXPECT_EQ("hello!", response_data); |
| 17216 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 17217 | auto entries = log.GetEntries(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17218 | ExpectLogContainsSomewhere( |
| 17219 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17220 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17221 | } |
| 17222 | |
| 17223 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 17224 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 17225 | // portions of the response. |
| 17226 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 17227 | // Two hosts resolve to the same IP address. |
| 17228 | const std::string ip_addr = "1.2.3.4"; |
| 17229 | IPAddress ip; |
| 17230 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 17231 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 17232 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17233 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17234 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 17235 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 17236 | |
| 17237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17238 | |
| 17239 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17240 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17241 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 17242 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17243 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17244 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17245 | spdy::SpdySerializedFrame rst( |
| 17246 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17247 | MockWrite writes1[] = { |
| 17248 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 17249 | CreateMockWrite(rst, 6), |
| 17250 | }; |
| 17251 | |
| 17252 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17253 | spdy::SpdySerializedFrame resp1( |
| 17254 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 17255 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 17256 | spdy::Http2HeaderBlock response_headers; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17257 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 17258 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17259 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 17260 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 17261 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 17262 | |
| 17263 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17264 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17265 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 17266 | |
| 17267 | AddSSLSocketData(); |
| 17268 | |
| 17269 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 17270 | // Retry again. |
| 17271 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17272 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17273 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 17274 | MockWrite writes2[] = { |
| 17275 | CreateMockWrite(req3, 0), |
| 17276 | }; |
| 17277 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17278 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17279 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17280 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17281 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 17282 | MockRead(ASYNC, 0, 3)}; |
| 17283 | |
| 17284 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17285 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17286 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 17287 | |
| 17288 | AddSSLSocketData(); |
| 17289 | |
| 17290 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17291 | int rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 17292 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 17293 | base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17294 | EXPECT_THAT(rv, IsOk()); |
| 17295 | |
| 17296 | HttpRequestInfo request1; |
| 17297 | request1.method = "GET"; |
| 17298 | request1.url = GURL("https://www.example.org/"); |
| 17299 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17300 | request1.traffic_annotation = |
| 17301 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17302 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 17303 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17304 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17305 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 17306 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17307 | rv = callback.WaitForResult(); |
| 17308 | EXPECT_THAT(rv, IsOk()); |
| 17309 | |
| 17310 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 17311 | ASSERT_TRUE(response); |
| 17312 | ASSERT_TRUE(response->headers); |
| 17313 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 17314 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 17315 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 17316 | std::string response_data; |
| 17317 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 17318 | EXPECT_EQ("hello!", response_data); |
| 17319 | |
| 17320 | HttpRequestInfo request2; |
| 17321 | request2.method = "GET"; |
| 17322 | request2.url = GURL("https://mail.example.org/"); |
| 17323 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17324 | request2.traffic_annotation = |
| 17325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17326 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 17327 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 17328 | RecordingBoundTestNetLog log; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 17329 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 17330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17331 | rv = callback.WaitForResult(); |
| 17332 | EXPECT_THAT(rv, IsOk()); |
| 17333 | |
| 17334 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 17335 | // caller. |
| 17336 | response = trans2.GetResponseInfo(); |
| 17337 | ASSERT_TRUE(response); |
| 17338 | ASSERT_TRUE(response->headers); |
| 17339 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 17340 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 17341 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 17342 | EXPECT_TRUE(response->ssl_info.cert); |
| 17343 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 17344 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 17345 | } |
| 17346 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17347 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 17348 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 17349 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 17350 | session_deps_.host_resolver = |
| 17351 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17353 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 17354 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17355 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17356 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17357 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17358 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17359 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 17360 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17361 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17362 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17363 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17364 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17365 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17366 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17367 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17368 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17369 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17370 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17371 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17372 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17373 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 17374 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17375 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17376 | }; |
| 17377 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 17378 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 17379 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17380 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17381 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17382 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 17383 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17384 | HttpRequestInfo request1; |
| 17385 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17386 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17387 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17388 | request1.traffic_annotation = |
| 17389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17390 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17392 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17394 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17395 | |
| 17396 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17397 | ASSERT_TRUE(response); |
| 17398 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17399 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17400 | |
| 17401 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17402 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17403 | EXPECT_EQ("hello!", response_data); |
| 17404 | |
| 17405 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 17406 | rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 17407 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 17408 | base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17409 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17410 | |
| 17411 | HttpRequestInfo request2; |
| 17412 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 17413 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17414 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17415 | request2.traffic_annotation = |
| 17416 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17417 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17418 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17419 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17421 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17422 | |
| 17423 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17424 | ASSERT_TRUE(response); |
| 17425 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17426 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17427 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17428 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17429 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17430 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 17431 | } |
| 17432 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17433 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17434 | const std::string https_url = "https://www.example.org:8080/"; |
| 17435 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17436 | |
| 17437 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17438 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17439 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17440 | |
| 17441 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17442 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17443 | }; |
| 17444 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17445 | spdy::SpdySerializedFrame resp1( |
| 17446 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17447 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17448 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17449 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17450 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17451 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17452 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 17453 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17454 | |
| 17455 | // HTTP GET for the HTTP URL |
| 17456 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17457 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 17458 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17459 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 17460 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17461 | }; |
| 17462 | |
| 17463 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 17464 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 17465 | MockRead(ASYNC, 2, "hello"), |
| 17466 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17467 | }; |
| 17468 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17469 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17470 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17471 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17472 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17474 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 17475 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17476 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17478 | |
| 17479 | // Start the first transaction to set up the SpdySession |
| 17480 | HttpRequestInfo request1; |
| 17481 | request1.method = "GET"; |
| 17482 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17483 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17484 | request1.traffic_annotation = |
| 17485 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17486 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17487 | TestCompletionCallback callback1; |
| 17488 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17489 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 17490 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17491 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17492 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17493 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 17494 | |
| 17495 | // Now, start the HTTP request |
| 17496 | HttpRequestInfo request2; |
| 17497 | request2.method = "GET"; |
| 17498 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17499 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17500 | request2.traffic_annotation = |
| 17501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17502 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17503 | TestCompletionCallback callback2; |
| 17504 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17505 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 17506 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17507 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17508 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17509 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 17510 | } |
| 17511 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17512 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 17513 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17514 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17515 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 17516 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17517 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17518 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17519 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17520 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17521 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17522 | |
| 17523 | // No data should be read from the alternative, because HTTP/1.1 is |
| 17524 | // negotiated. |
| 17525 | StaticSocketDataProvider data; |
| 17526 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17527 | |
| 17528 | // 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] | 17529 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17530 | // mocked. This way the request relies on the alternate Job. |
| 17531 | StaticSocketDataProvider data_refused; |
| 17532 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 17533 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 17534 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17535 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 17537 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17538 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 17539 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 17540 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 17541 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 17542 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17543 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17544 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17545 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17546 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17547 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17548 | request.traffic_annotation = |
| 17549 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17550 | TestCompletionCallback callback; |
| 17551 | |
| 17552 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17553 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17555 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17556 | } |
| 17557 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17558 | // 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] | 17559 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17560 | // succeeds, the request should succeed, even if the latter fails because |
| 17561 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17562 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17563 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 17564 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17565 | |
| 17566 | // Negotiate HTTP/1.1 with alternative. |
| 17567 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17568 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 17570 | |
| 17571 | // No data should be read from the alternative, because HTTP/1.1 is |
| 17572 | // negotiated. |
| 17573 | StaticSocketDataProvider data; |
| 17574 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17575 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17576 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17577 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17578 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 17580 | |
| 17581 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17582 | MockWrite("GET / HTTP/1.1\r\n" |
| 17583 | "Host: www.example.org\r\n" |
| 17584 | "Connection: keep-alive\r\n\r\n"), |
| 17585 | MockWrite("GET /second HTTP/1.1\r\n" |
| 17586 | "Host: www.example.org\r\n" |
| 17587 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17588 | }; |
| 17589 | |
| 17590 | MockRead http_reads[] = { |
| 17591 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17592 | MockRead("Content-Type: text/html\r\n"), |
| 17593 | MockRead("Content-Length: 6\r\n\r\n"), |
| 17594 | MockRead("foobar"), |
| 17595 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17596 | MockRead("Content-Type: text/html\r\n"), |
| 17597 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17598 | MockRead("another"), |
| 17599 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17600 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17601 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17602 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17603 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 17605 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17606 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 17607 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 17608 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 17609 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 17610 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17611 | |
| 17612 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 17613 | HttpRequestInfo request1; |
| 17614 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17615 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17616 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17617 | request1.traffic_annotation = |
| 17618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17619 | TestCompletionCallback callback1; |
| 17620 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17621 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17622 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17623 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17624 | |
| 17625 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17626 | ASSERT_TRUE(response1); |
| 17627 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17628 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 17629 | |
| 17630 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17631 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17632 | EXPECT_EQ("foobar", response_data1); |
| 17633 | |
| 17634 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 17635 | // for alternative service. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 17636 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 17637 | alternative_service, NetworkIsolationKey())); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17638 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17639 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17640 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17641 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17642 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 17643 | HttpRequestInfo request2; |
| 17644 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 17645 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17646 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17647 | request2.traffic_annotation = |
| 17648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17649 | TestCompletionCallback callback2; |
| 17650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17651 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17652 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17653 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17654 | |
| 17655 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17656 | ASSERT_TRUE(response2); |
| 17657 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17658 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 17659 | |
| 17660 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17661 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 17662 | EXPECT_EQ("another", response_data2); |
| 17663 | } |
| 17664 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17665 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 17666 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 17667 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17668 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17669 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17670 | HostPortPair alternative("alternative.example.org", 443); |
| 17671 | std::string origin_url = "https://origin.example.org:443"; |
| 17672 | std::string alternative_url = "https://alternative.example.org:443"; |
| 17673 | |
| 17674 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 17675 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17676 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17677 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17678 | |
| 17679 | // HTTP/1.1 data for |request1| and |request2|. |
| 17680 | MockWrite http_writes[] = { |
| 17681 | MockWrite( |
| 17682 | "GET / HTTP/1.1\r\n" |
| 17683 | "Host: alternative.example.org\r\n" |
| 17684 | "Connection: keep-alive\r\n\r\n"), |
| 17685 | MockWrite( |
| 17686 | "GET / HTTP/1.1\r\n" |
| 17687 | "Host: alternative.example.org\r\n" |
| 17688 | "Connection: keep-alive\r\n\r\n"), |
| 17689 | }; |
| 17690 | |
| 17691 | MockRead http_reads[] = { |
| 17692 | MockRead( |
| 17693 | "HTTP/1.1 200 OK\r\n" |
| 17694 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 17695 | "Content-Length: 40\r\n\r\n" |
| 17696 | "first HTTP/1.1 response from alternative"), |
| 17697 | MockRead( |
| 17698 | "HTTP/1.1 200 OK\r\n" |
| 17699 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 17700 | "Content-Length: 41\r\n\r\n" |
| 17701 | "second HTTP/1.1 response from alternative"), |
| 17702 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17703 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17704 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17705 | |
| 17706 | // This test documents that an alternate Job should not pool to an already |
| 17707 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17708 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17709 | StaticSocketDataProvider data_refused; |
| 17710 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 17711 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 17712 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 17713 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17714 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 17715 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17716 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 17717 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 17718 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 17719 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 17720 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17721 | |
| 17722 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17723 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17724 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17725 | request1.method = "GET"; |
| 17726 | request1.url = GURL(alternative_url); |
| 17727 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17728 | request1.traffic_annotation = |
| 17729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17730 | TestCompletionCallback callback1; |
| 17731 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17732 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17733 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17734 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17735 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17736 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17737 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17738 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17739 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 17740 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17741 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17742 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 17743 | |
| 17744 | // Request for origin.example.org, which has an alternative service. This |
| 17745 | // will start two Jobs: the alternative looks for connections to pool to, |
| 17746 | // 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] | 17747 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17748 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17749 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17750 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17751 | request2.method = "GET"; |
| 17752 | request2.url = GURL(origin_url); |
| 17753 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17754 | request2.traffic_annotation = |
| 17755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17756 | TestCompletionCallback callback2; |
| 17757 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17758 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17759 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17760 | |
| 17761 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 17762 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17763 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 17764 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17765 | request3.method = "GET"; |
| 17766 | request3.url = GURL(alternative_url); |
| 17767 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17768 | request3.traffic_annotation = |
| 17769 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17770 | TestCompletionCallback callback3; |
| 17771 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17772 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17773 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17774 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17775 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17776 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17777 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17778 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17779 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 17780 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17781 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 17782 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 17783 | } |
| 17784 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17785 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17786 | const std::string https_url = "https://www.example.org:8080/"; |
| 17787 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17788 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17789 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17790 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17791 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17792 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17793 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 17794 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 17795 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 17796 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17797 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17798 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17799 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 17800 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 17801 | |
| 17802 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 17803 | spdy::Http2HeaderBlock req2_block; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17804 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 17805 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 17806 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 17807 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 17808 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17809 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17810 | |
| 17811 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17812 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 17813 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17814 | }; |
| 17815 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17816 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17817 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17818 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17819 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17820 | spdy::SpdySerializedFrame body1( |
| 17821 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 17822 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17823 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17824 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17825 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17826 | spdy::SpdySerializedFrame resp2( |
| 17827 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17828 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17829 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17830 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17831 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17832 | CreateMockRead(wrapped_resp1, 4), |
| 17833 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17834 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17835 | CreateMockRead(resp2, 8), |
| 17836 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17837 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 17838 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17839 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17840 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17841 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 17842 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17843 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17844 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 17845 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17846 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 17847 | RecordingTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17848 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17849 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17850 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17852 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17853 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17854 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17855 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17856 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17857 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17858 | |
| 17859 | // Start the first transaction to set up the SpdySession |
| 17860 | HttpRequestInfo request1; |
| 17861 | request1.method = "GET"; |
| 17862 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17863 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17864 | request1.traffic_annotation = |
| 17865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17866 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17867 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17868 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17869 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17870 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 17871 | data1.RunUntilPaused(); |
| 17872 | base::RunLoop().RunUntilIdle(); |
| 17873 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17874 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17875 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 17876 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 17877 | LoadTimingInfo load_timing_info1; |
| 17878 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 17879 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 17880 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 17881 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17882 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17883 | HttpRequestInfo request2; |
| 17884 | request2.method = "GET"; |
| 17885 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17886 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17887 | request2.traffic_annotation = |
| 17888 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17889 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17890 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17891 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17892 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17893 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 17894 | data1.RunUntilPaused(); |
| 17895 | base::RunLoop().RunUntilIdle(); |
| 17896 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17897 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17898 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 17899 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 17900 | |
| 17901 | LoadTimingInfo load_timing_info2; |
| 17902 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 17903 | // The established SPDY sessions is considered reused by the HTTP request. |
| 17904 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 17905 | // HTTP requests over a SPDY session should have a different connection |
| 17906 | // socket_log_id than requests over a tunnel. |
| 17907 | 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] | 17908 | } |
| 17909 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17910 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 17911 | // that we do not pool other origins that resolve to the same IP when |
| 17912 | // the certificate does not match the new origin. |
| 17913 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17914 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17915 | const std::string url1 = "http://www.example.org/"; |
| 17916 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17917 | const std::string ip_addr = "1.2.3.4"; |
| 17918 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17919 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17920 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17921 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17922 | // SPDY GET for HTTP URL (through SPDY proxy) |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 17923 | spdy::Http2HeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17924 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17925 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17926 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17927 | |
| 17928 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17929 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17930 | }; |
| 17931 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17932 | spdy::SpdySerializedFrame resp1( |
| 17933 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17934 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17935 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17936 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 17937 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17938 | }; |
| 17939 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17940 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 17941 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 17942 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17943 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 17944 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17945 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17946 | |
| 17947 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17948 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17949 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17950 | |
| 17951 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17952 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17953 | }; |
| 17954 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17955 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17956 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17957 | spdy::SpdySerializedFrame body2( |
| 17958 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17959 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17960 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17961 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17962 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17963 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17964 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17965 | |
| 17966 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 17967 | // all others direct. |
| 17968 | ProxyConfig proxy_config; |
| 17969 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17970 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 17971 | std::make_unique<ConfiguredProxyResolutionService>( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17972 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17973 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 17974 | nullptr, nullptr, /*quick_check_enabled=*/true); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17975 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17976 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17977 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17978 | // Load a valid cert. Note, that this does not need to |
| 17979 | // be valid for proxy because the MockSSLClientSocket does |
| 17980 | // not actually verify it. But SpdySession will use this |
| 17981 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17982 | ssl1.ssl_info.cert = |
| 17983 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 17984 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17986 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17987 | |
| 17988 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17989 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17991 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17992 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17993 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17994 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17995 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17996 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17997 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17998 | |
| 17999 | // Start the first transaction to set up the SpdySession |
| 18000 | HttpRequestInfo request1; |
| 18001 | request1.method = "GET"; |
| 18002 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18003 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18004 | request1.traffic_annotation = |
| 18005 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 18006 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18007 | TestCompletionCallback callback1; |
| 18008 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18009 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 18010 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 18011 | data1.RunUntilPaused(); |
| 18012 | base::RunLoop().RunUntilIdle(); |
| 18013 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18014 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18015 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18016 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 18017 | |
| 18018 | // Now, start the HTTP request |
| 18019 | HttpRequestInfo request2; |
| 18020 | request2.method = "GET"; |
| 18021 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18022 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18023 | request2.traffic_annotation = |
| 18024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 18025 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18026 | TestCompletionCallback callback2; |
| 18027 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18028 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 18029 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18030 | |
| 18031 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18032 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 18033 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 18034 | } |
| 18035 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18036 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 18037 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 18038 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 18039 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18040 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18041 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18042 | |
| 18043 | MockRead reads1[] = { |
| 18044 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 18045 | }; |
| 18046 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18047 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18048 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18049 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 18050 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18051 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18052 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18053 | }; |
| 18054 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 18055 | spdy::SpdySerializedFrame resp2( |
| 18056 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18057 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18058 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18059 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 18060 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18061 | }; |
| 18062 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18063 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18064 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18065 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 18066 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 18067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18068 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18069 | |
| 18070 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 18071 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 18072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18073 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18074 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18075 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 18076 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18077 | |
| 18078 | // Start the first transaction to set up the SpdySession and verify that |
| 18079 | // connection was closed. |
| 18080 | HttpRequestInfo request1; |
| 18081 | request1.method = "GET"; |
| 18082 | request1.url = GURL(https_url); |
| 18083 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18084 | request1.traffic_annotation = |
| 18085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 18086 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18087 | TestCompletionCallback callback1; |
| 18088 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18089 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18090 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18091 | |
| 18092 | // Now, start the second request and make sure it succeeds. |
| 18093 | HttpRequestInfo request2; |
| 18094 | request2.method = "GET"; |
| 18095 | request2.url = GURL(https_url); |
| 18096 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18097 | request2.traffic_annotation = |
| 18098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 18099 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18100 | TestCompletionCallback callback2; |
| 18101 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18102 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18103 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18104 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 18105 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 18106 | } |
| 18107 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18108 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18109 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 18110 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18111 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 18112 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18113 | |
| 18114 | // Use two different hosts with different IPs so they don't get pooled. |
| 18115 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 18116 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18118 | |
| 18119 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 18120 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18121 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 18122 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18123 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18125 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18126 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 18127 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18128 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18129 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18130 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18131 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 18132 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18133 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18134 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18135 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18136 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 18137 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18138 | }; |
| 18139 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 18140 | // Use a separate test instance for the separate SpdySession that will be |
| 18141 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18142 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18143 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 18144 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18145 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18146 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 18147 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18148 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18149 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18150 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18151 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 18152 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 18153 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18154 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18155 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 18156 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 18157 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18158 | }; |
| 18159 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18160 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 18161 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18162 | |
| 18163 | MockWrite http_write[] = { |
| 18164 | MockWrite("GET / HTTP/1.1\r\n" |
| 18165 | "Host: www.a.com\r\n" |
| 18166 | "Connection: keep-alive\r\n\r\n"), |
| 18167 | }; |
| 18168 | |
| 18169 | MockRead http_read[] = { |
| 18170 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18171 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18172 | MockRead("Content-Length: 6\r\n\r\n"), |
| 18173 | MockRead("hello!"), |
| 18174 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18175 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18176 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 18177 | |
| 18178 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 18179 | SpdySessionKey spdy_session_key_a( |
| 18180 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 18181 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 18182 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18183 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18184 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18185 | |
| 18186 | TestCompletionCallback callback; |
| 18187 | HttpRequestInfo request1; |
| 18188 | request1.method = "GET"; |
| 18189 | request1.url = GURL("https://www.a.com/"); |
| 18190 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18191 | request1.traffic_annotation = |
| 18192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18193 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18194 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18195 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18196 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18198 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18199 | |
| 18200 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18201 | ASSERT_TRUE(response); |
| 18202 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 18203 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18204 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 18205 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18206 | |
| 18207 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18208 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18209 | EXPECT_EQ("hello!", response_data); |
| 18210 | trans.reset(); |
| 18211 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18212 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18213 | |
| 18214 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 18215 | SpdySessionKey spdy_session_key_b( |
| 18216 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 18217 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 18218 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18219 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18220 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18221 | HttpRequestInfo request2; |
| 18222 | request2.method = "GET"; |
| 18223 | request2.url = GURL("https://www.b.com/"); |
| 18224 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18225 | request2.traffic_annotation = |
| 18226 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18227 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18228 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18229 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18230 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18231 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18232 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18233 | |
| 18234 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18235 | ASSERT_TRUE(response); |
| 18236 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 18237 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18238 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 18239 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18240 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18241 | EXPECT_EQ("hello!", response_data); |
| 18242 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18243 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18244 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18245 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18246 | |
| 18247 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 18248 | SpdySessionKey spdy_session_key_a1( |
| 18249 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 18250 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 18251 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18252 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18253 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18254 | HttpRequestInfo request3; |
| 18255 | request3.method = "GET"; |
| 18256 | request3.url = GURL("http://www.a.com/"); |
| 18257 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18258 | request3.traffic_annotation = |
| 18259 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18260 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18261 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18262 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18263 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18265 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18266 | |
| 18267 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18268 | ASSERT_TRUE(response); |
| 18269 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18270 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 18271 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 18272 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18273 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18274 | EXPECT_EQ("hello!", response_data); |
| 18275 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18276 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18277 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 18278 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 18279 | } |
| 18280 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18281 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18282 | HttpRequestInfo request; |
| 18283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18284 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18285 | request.traffic_annotation = |
| 18286 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18287 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18289 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18290 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18291 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18292 | StaticSocketDataProvider data; |
| 18293 | data.set_connect_data(mock_connect); |
| 18294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18295 | |
| 18296 | TestCompletionCallback callback; |
| 18297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18298 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18300 | |
| 18301 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18302 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18303 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18304 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18305 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18306 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18307 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18308 | |
| 18309 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18310 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18311 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18312 | } |
| 18313 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18314 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18315 | HttpRequestInfo request; |
| 18316 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18317 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18318 | request.traffic_annotation = |
| 18319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18322 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18323 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18324 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18325 | StaticSocketDataProvider data; |
| 18326 | data.set_connect_data(mock_connect); |
| 18327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18328 | |
| 18329 | TestCompletionCallback callback; |
| 18330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18331 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18333 | |
| 18334 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18335 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18336 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18337 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18338 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 18339 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18340 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18341 | |
| 18342 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18343 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 18344 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18345 | } |
| 18346 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18347 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18348 | HttpRequestInfo request; |
| 18349 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18350 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18351 | request.traffic_annotation = |
| 18352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18353 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18355 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18356 | |
| 18357 | MockWrite data_writes[] = { |
| 18358 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18359 | }; |
| 18360 | MockRead data_reads[] = { |
| 18361 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 18362 | }; |
| 18363 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18364 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18365 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18366 | |
| 18367 | TestCompletionCallback callback; |
| 18368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18369 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18371 | |
| 18372 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18373 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18374 | } |
| 18375 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18376 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18377 | HttpRequestInfo request; |
| 18378 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18379 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18380 | request.traffic_annotation = |
| 18381 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18382 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18383 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18384 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18385 | |
| 18386 | MockWrite data_writes[] = { |
| 18387 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 18388 | }; |
| 18389 | MockRead data_reads[] = { |
| 18390 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 18391 | }; |
| 18392 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18393 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18394 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18395 | |
| 18396 | TestCompletionCallback callback; |
| 18397 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18398 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18400 | |
| 18401 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18402 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18403 | } |
| 18404 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18405 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18406 | HttpRequestInfo request; |
| 18407 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18408 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18409 | request.traffic_annotation = |
| 18410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18414 | |
| 18415 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18416 | MockWrite( |
| 18417 | "GET / HTTP/1.1\r\n" |
| 18418 | "Host: www.example.org\r\n" |
| 18419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18420 | }; |
| 18421 | MockRead data_reads[] = { |
| 18422 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18423 | }; |
| 18424 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18425 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18427 | |
| 18428 | TestCompletionCallback callback; |
| 18429 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18430 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18432 | |
| 18433 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18434 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18435 | } |
| 18436 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18437 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18438 | HttpRequestInfo request; |
| 18439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18440 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18441 | request.traffic_annotation = |
| 18442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18443 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18444 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18445 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18446 | |
| 18447 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18448 | MockWrite( |
| 18449 | "GET / HTTP/1.1\r\n" |
| 18450 | "Host: www.example.org\r\n" |
| 18451 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18452 | }; |
| 18453 | MockRead data_reads[] = { |
| 18454 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18455 | }; |
| 18456 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18457 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18459 | |
| 18460 | TestCompletionCallback callback; |
| 18461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18464 | |
| 18465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18466 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 18467 | } |
| 18468 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18469 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 18470 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18471 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18472 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 18473 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18474 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 18475 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18476 | |
| 18477 | // Set up SSL request. |
| 18478 | |
| 18479 | HttpRequestInfo ssl_request; |
| 18480 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18481 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18482 | ssl_request.traffic_annotation = |
| 18483 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18484 | |
| 18485 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18486 | MockWrite( |
| 18487 | "GET / HTTP/1.1\r\n" |
| 18488 | "Host: www.example.org\r\n" |
| 18489 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18490 | }; |
| 18491 | MockRead ssl_reads[] = { |
| 18492 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18493 | MockRead("Content-Length: 11\r\n\r\n"), |
| 18494 | MockRead("hello world"), |
| 18495 | MockRead(SYNCHRONOUS, OK), |
| 18496 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18497 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18498 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 18499 | |
| 18500 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18502 | |
| 18503 | // Set up HTTP request. |
| 18504 | |
| 18505 | HttpRequestInfo http_request; |
| 18506 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18507 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18508 | http_request.traffic_annotation = |
| 18509 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18510 | |
| 18511 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18512 | MockWrite( |
| 18513 | "GET / HTTP/1.1\r\n" |
| 18514 | "Host: www.example.org\r\n" |
| 18515 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18516 | }; |
| 18517 | MockRead http_reads[] = { |
| 18518 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18519 | MockRead("Content-Length: 7\r\n\r\n"), |
| 18520 | MockRead("falafel"), |
| 18521 | MockRead(SYNCHRONOUS, OK), |
| 18522 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18523 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18524 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 18525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18527 | |
| 18528 | // Start the SSL request. |
| 18529 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18530 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18531 | ASSERT_EQ(ERR_IO_PENDING, |
| 18532 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 18533 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18534 | |
| 18535 | // Start the HTTP request. Pool should stall. |
| 18536 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18537 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18538 | ASSERT_EQ(ERR_IO_PENDING, |
| 18539 | http_trans.Start(&http_request, http_callback.callback(), |
| 18540 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18541 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18542 | |
| 18543 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18544 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18545 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18546 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18547 | EXPECT_EQ("hello world", response_data); |
| 18548 | |
| 18549 | // The SSL socket should automatically be closed, so the HTTP request can |
| 18550 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 18551 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18552 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18553 | |
| 18554 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18555 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18556 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18557 | EXPECT_EQ("falafel", response_data); |
| 18558 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18559 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18560 | } |
| 18561 | |
| 18562 | // Tests that when a SSL connection is established but there's no corresponding |
| 18563 | // request that needs it, the new socket is closed if the transport socket pool |
| 18564 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18565 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18566 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 18567 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18568 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 18569 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 18570 | |
| 18571 | // Set up an ssl request. |
| 18572 | |
| 18573 | HttpRequestInfo ssl_request; |
| 18574 | ssl_request.method = "GET"; |
| 18575 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18576 | ssl_request.traffic_annotation = |
| 18577 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18578 | |
| 18579 | // No data will be sent on the SSL socket. |
| 18580 | StaticSocketDataProvider ssl_data; |
| 18581 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 18582 | |
| 18583 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18585 | |
| 18586 | // Set up HTTP request. |
| 18587 | |
| 18588 | HttpRequestInfo http_request; |
| 18589 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18590 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18591 | http_request.traffic_annotation = |
| 18592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18593 | |
| 18594 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18595 | MockWrite( |
| 18596 | "GET / HTTP/1.1\r\n" |
| 18597 | "Host: www.example.org\r\n" |
| 18598 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18599 | }; |
| 18600 | MockRead http_reads[] = { |
| 18601 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18602 | MockRead("Content-Length: 7\r\n\r\n"), |
| 18603 | MockRead("falafel"), |
| 18604 | MockRead(SYNCHRONOUS, OK), |
| 18605 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18606 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18607 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 18608 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18610 | |
| 18611 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 18612 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 18613 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 18614 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 18615 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18616 | |
| 18617 | // Start the HTTP request. Pool should stall. |
| 18618 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18619 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18620 | ASSERT_EQ(ERR_IO_PENDING, |
| 18621 | http_trans.Start(&http_request, http_callback.callback(), |
| 18622 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18623 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18624 | |
| 18625 | // The SSL connection will automatically be closed once the connection is |
| 18626 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18627 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18628 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18629 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18630 | EXPECT_EQ("falafel", response_data); |
| 18631 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 18632 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 18633 | } |
| 18634 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18635 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18636 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18637 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18638 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18639 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18640 | |
| 18641 | HttpRequestInfo request; |
| 18642 | request.method = "POST"; |
| 18643 | request.url = GURL("http://www.foo.com/"); |
| 18644 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18645 | request.traffic_annotation = |
| 18646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18649 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18650 | // Send headers successfully, but get an error while sending the body. |
| 18651 | MockWrite data_writes[] = { |
| 18652 | MockWrite("POST / HTTP/1.1\r\n" |
| 18653 | "Host: www.foo.com\r\n" |
| 18654 | "Connection: keep-alive\r\n" |
| 18655 | "Content-Length: 3\r\n\r\n"), |
| 18656 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18657 | }; |
| 18658 | |
| 18659 | MockRead data_reads[] = { |
| 18660 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18661 | MockRead("hello world"), |
| 18662 | MockRead(SYNCHRONOUS, OK), |
| 18663 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18664 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18666 | |
| 18667 | TestCompletionCallback callback; |
| 18668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18671 | |
| 18672 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18673 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18675 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18676 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18677 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18678 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18679 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18680 | |
| 18681 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18682 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18683 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18684 | EXPECT_EQ("hello world", response_data); |
| 18685 | } |
| 18686 | |
| 18687 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 18688 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18689 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18690 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18692 | MockWrite data_writes[] = { |
| 18693 | MockWrite("GET / HTTP/1.1\r\n" |
| 18694 | "Host: www.foo.com\r\n" |
| 18695 | "Connection: keep-alive\r\n\r\n"), |
| 18696 | MockWrite("POST / HTTP/1.1\r\n" |
| 18697 | "Host: www.foo.com\r\n" |
| 18698 | "Connection: keep-alive\r\n" |
| 18699 | "Content-Length: 3\r\n\r\n"), |
| 18700 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18701 | }; |
| 18702 | |
| 18703 | MockRead data_reads[] = { |
| 18704 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 18705 | "Content-Length: 14\r\n\r\n"), |
| 18706 | MockRead("first response"), |
| 18707 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 18708 | "Content-Length: 15\r\n\r\n"), |
| 18709 | MockRead("second response"), |
| 18710 | MockRead(SYNCHRONOUS, OK), |
| 18711 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18712 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18713 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18714 | |
| 18715 | TestCompletionCallback callback; |
| 18716 | HttpRequestInfo request1; |
| 18717 | request1.method = "GET"; |
| 18718 | request1.url = GURL("http://www.foo.com/"); |
| 18719 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18720 | request1.traffic_annotation = |
| 18721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18722 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18723 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18724 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18725 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18727 | |
| 18728 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18729 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18730 | |
| 18731 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18732 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18733 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18734 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18735 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 18736 | |
| 18737 | std::string response_data1; |
| 18738 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18740 | EXPECT_EQ("first response", response_data1); |
| 18741 | // Delete the transaction to release the socket back into the socket pool. |
| 18742 | trans1.reset(); |
| 18743 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18744 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18745 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18746 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18747 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18748 | |
| 18749 | HttpRequestInfo request2; |
| 18750 | request2.method = "POST"; |
| 18751 | request2.url = GURL("http://www.foo.com/"); |
| 18752 | request2.upload_data_stream = &upload_data_stream; |
| 18753 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18754 | request2.traffic_annotation = |
| 18755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18757 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18758 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18760 | |
| 18761 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18762 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18764 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18765 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18766 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18767 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18768 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 18769 | |
| 18770 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18771 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18772 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18773 | EXPECT_EQ("second response", response_data2); |
| 18774 | } |
| 18775 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18776 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18777 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18778 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18779 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18780 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18781 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18782 | |
| 18783 | HttpRequestInfo request; |
| 18784 | request.method = "POST"; |
| 18785 | request.url = GURL("http://www.foo.com/"); |
| 18786 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18787 | request.traffic_annotation = |
| 18788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18789 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18792 | // Send headers successfully, but get an error while sending the body. |
| 18793 | MockWrite data_writes[] = { |
| 18794 | MockWrite("POST / HTTP/1.1\r\n" |
| 18795 | "Host: www.foo.com\r\n" |
| 18796 | "Connection: keep-alive\r\n" |
| 18797 | "Content-Length: 3\r\n\r\n" |
| 18798 | "fo"), |
| 18799 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18800 | }; |
| 18801 | |
| 18802 | MockRead data_reads[] = { |
| 18803 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18804 | MockRead("hello world"), |
| 18805 | MockRead(SYNCHRONOUS, OK), |
| 18806 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18807 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18809 | |
| 18810 | TestCompletionCallback callback; |
| 18811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18814 | |
| 18815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18818 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18819 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18820 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18821 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18822 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18823 | |
| 18824 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18825 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18826 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18827 | EXPECT_EQ("hello world", response_data); |
| 18828 | } |
| 18829 | |
| 18830 | // This tests the more common case than the previous test, where headers and |
| 18831 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18832 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 18833 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18834 | |
| 18835 | HttpRequestInfo request; |
| 18836 | request.method = "POST"; |
| 18837 | request.url = GURL("http://www.foo.com/"); |
| 18838 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18839 | request.traffic_annotation = |
| 18840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18841 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18843 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18844 | // Send headers successfully, but get an error while sending the body. |
| 18845 | MockWrite data_writes[] = { |
| 18846 | MockWrite("POST / HTTP/1.1\r\n" |
| 18847 | "Host: www.foo.com\r\n" |
| 18848 | "Connection: keep-alive\r\n" |
| 18849 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18850 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18851 | }; |
| 18852 | |
| 18853 | MockRead data_reads[] = { |
| 18854 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18855 | MockRead("hello world"), |
| 18856 | MockRead(SYNCHRONOUS, OK), |
| 18857 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18858 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18860 | |
| 18861 | TestCompletionCallback callback; |
| 18862 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18863 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18865 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 18866 | // they can't be merged with the body in a single send. Not currently |
| 18867 | // necessary since a chunked body is never merged with headers, but this makes |
| 18868 | // the test more future proof. |
| 18869 | base::RunLoop().RunUntilIdle(); |
| 18870 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 18871 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18872 | |
| 18873 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18874 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18876 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18877 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18878 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18879 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18880 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18881 | |
| 18882 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18883 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18885 | EXPECT_EQ("hello world", response_data); |
| 18886 | } |
| 18887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18888 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18889 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18890 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18891 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18892 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18893 | |
| 18894 | HttpRequestInfo request; |
| 18895 | request.method = "POST"; |
| 18896 | request.url = GURL("http://www.foo.com/"); |
| 18897 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18898 | request.traffic_annotation = |
| 18899 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18900 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18901 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18902 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18903 | |
| 18904 | MockWrite data_writes[] = { |
| 18905 | MockWrite("POST / HTTP/1.1\r\n" |
| 18906 | "Host: www.foo.com\r\n" |
| 18907 | "Connection: keep-alive\r\n" |
| 18908 | "Content-Length: 3\r\n\r\n"), |
| 18909 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18910 | }; |
| 18911 | |
| 18912 | MockRead data_reads[] = { |
| 18913 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 18914 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 18915 | MockRead("hello world"), |
| 18916 | MockRead(SYNCHRONOUS, OK), |
| 18917 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18918 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18919 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18920 | |
| 18921 | TestCompletionCallback callback; |
| 18922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18923 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18925 | |
| 18926 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18927 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18929 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18930 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18931 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18932 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18933 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 18934 | |
| 18935 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18936 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18937 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18938 | EXPECT_EQ("hello world", response_data); |
| 18939 | } |
| 18940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18941 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18942 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18943 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18944 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18945 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18946 | |
| 18947 | HttpRequestInfo request; |
| 18948 | request.method = "POST"; |
| 18949 | request.url = GURL("http://www.foo.com/"); |
| 18950 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18951 | request.traffic_annotation = |
| 18952 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18953 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18954 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18955 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18956 | // Send headers successfully, but get an error while sending the body. |
| 18957 | MockWrite data_writes[] = { |
| 18958 | MockWrite("POST / HTTP/1.1\r\n" |
| 18959 | "Host: www.foo.com\r\n" |
| 18960 | "Connection: keep-alive\r\n" |
| 18961 | "Content-Length: 3\r\n\r\n"), |
| 18962 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18963 | }; |
| 18964 | |
| 18965 | MockRead data_reads[] = { |
| 18966 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 18967 | MockRead("hello world"), |
| 18968 | MockRead(SYNCHRONOUS, OK), |
| 18969 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18970 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18971 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18972 | |
| 18973 | TestCompletionCallback callback; |
| 18974 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18975 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18977 | |
| 18978 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18979 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18980 | } |
| 18981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18982 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18983 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18984 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18985 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18986 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18987 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18988 | |
| 18989 | HttpRequestInfo request; |
| 18990 | request.method = "POST"; |
| 18991 | request.url = GURL("http://www.foo.com/"); |
| 18992 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18993 | request.traffic_annotation = |
| 18994 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18995 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18997 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18998 | // Send headers successfully, but get an error while sending the body. |
| 18999 | MockWrite data_writes[] = { |
| 19000 | MockWrite("POST / HTTP/1.1\r\n" |
| 19001 | "Host: www.foo.com\r\n" |
| 19002 | "Connection: keep-alive\r\n" |
| 19003 | "Content-Length: 3\r\n\r\n"), |
| 19004 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 19005 | }; |
| 19006 | |
| 19007 | MockRead data_reads[] = { |
| 19008 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 19009 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 19010 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 19011 | MockRead("Content-Length: 0\r\n\r\n"), |
| 19012 | MockRead(SYNCHRONOUS, OK), |
| 19013 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19014 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19015 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19016 | |
| 19017 | TestCompletionCallback callback; |
| 19018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19021 | |
| 19022 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19023 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19024 | } |
| 19025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19026 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19027 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19028 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19029 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19030 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19031 | |
| 19032 | HttpRequestInfo request; |
| 19033 | request.method = "POST"; |
| 19034 | request.url = GURL("http://www.foo.com/"); |
| 19035 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19036 | request.traffic_annotation = |
| 19037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19041 | // Send headers successfully, but get an error while sending the body. |
| 19042 | MockWrite data_writes[] = { |
| 19043 | MockWrite("POST / HTTP/1.1\r\n" |
| 19044 | "Host: www.foo.com\r\n" |
| 19045 | "Connection: keep-alive\r\n" |
| 19046 | "Content-Length: 3\r\n\r\n"), |
| 19047 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 19048 | }; |
| 19049 | |
| 19050 | MockRead data_reads[] = { |
| 19051 | MockRead("HTTP 0.9 rocks!"), |
| 19052 | MockRead(SYNCHRONOUS, OK), |
| 19053 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19054 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19055 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19056 | |
| 19057 | TestCompletionCallback callback; |
| 19058 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19059 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19061 | |
| 19062 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19063 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19064 | } |
| 19065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19066 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19067 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19068 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19069 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19070 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19071 | |
| 19072 | HttpRequestInfo request; |
| 19073 | request.method = "POST"; |
| 19074 | request.url = GURL("http://www.foo.com/"); |
| 19075 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19076 | request.traffic_annotation = |
| 19077 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19078 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19079 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19080 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19081 | // Send headers successfully, but get an error while sending the body. |
| 19082 | MockWrite data_writes[] = { |
| 19083 | MockWrite("POST / HTTP/1.1\r\n" |
| 19084 | "Host: www.foo.com\r\n" |
| 19085 | "Connection: keep-alive\r\n" |
| 19086 | "Content-Length: 3\r\n\r\n"), |
| 19087 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 19088 | }; |
| 19089 | |
| 19090 | MockRead data_reads[] = { |
| 19091 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 19092 | MockRead(SYNCHRONOUS, OK), |
| 19093 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19094 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19095 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19096 | |
| 19097 | TestCompletionCallback callback; |
| 19098 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19099 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19100 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19101 | |
| 19102 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19103 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 19104 | } |
| 19105 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19106 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 19107 | |
| 19108 | namespace { |
| 19109 | |
| 19110 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 19111 | headers->SetHeader("Connection", "Upgrade"); |
| 19112 | headers->SetHeader("Upgrade", "websocket"); |
| 19113 | headers->SetHeader("Origin", "http://www.example.org"); |
| 19114 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19115 | } |
| 19116 | |
| 19117 | } // namespace |
| 19118 | |
| 19119 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19120 | for (bool secure : {true, false}) { |
| 19121 | MockWrite data_writes[] = { |
| 19122 | MockWrite("GET / HTTP/1.1\r\n" |
| 19123 | "Host: www.example.org\r\n" |
| 19124 | "Connection: Upgrade\r\n" |
| 19125 | "Upgrade: websocket\r\n" |
| 19126 | "Origin: http://www.example.org\r\n" |
| 19127 | "Sec-WebSocket-Version: 13\r\n" |
| 19128 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 19129 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 19130 | "client_max_window_bits\r\n\r\n")}; |
| 19131 | |
| 19132 | MockRead data_reads[] = { |
| 19133 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 19134 | "Upgrade: websocket\r\n" |
| 19135 | "Connection: Upgrade\r\n" |
| 19136 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 19137 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19138 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19140 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19141 | if (secure) |
| 19142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19143 | |
| 19144 | HttpRequestInfo request; |
| 19145 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19146 | request.url = |
| 19147 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 19148 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19149 | request.traffic_annotation = |
| 19150 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19151 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19152 | TestWebSocketHandshakeStreamCreateHelper |
| 19153 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19154 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19156 | HttpNetworkTransaction trans(LOW, session.get()); |
| 19157 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19158 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19159 | |
| 19160 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19161 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19163 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 19164 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 19165 | ASSERT_TRUE(stream_request); |
| 19166 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 19167 | stream_request->websocket_handshake_stream_create_helper()); |
| 19168 | |
| 19169 | rv = callback.WaitForResult(); |
| 19170 | EXPECT_THAT(rv, IsOk()); |
| 19171 | |
| 19172 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 19173 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19174 | } |
| 19175 | } |
| 19176 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19177 | // Verify that proxy headers are not sent to the destination server when |
| 19178 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19179 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19180 | HttpRequestInfo request; |
| 19181 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 19182 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19183 | request.traffic_annotation = |
| 19184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19185 | AddWebSocketHeaders(&request.extra_headers); |
| 19186 | |
| 19187 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 19188 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19189 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 19190 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19191 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19193 | |
| 19194 | // Since a proxy is configured, try to establish a tunnel. |
| 19195 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 19196 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19197 | "Host: www.example.org:443\r\n" |
| 19198 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19199 | |
| 19200 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19201 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 19202 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19203 | "Host: www.example.org:443\r\n" |
| 19204 | "Proxy-Connection: keep-alive\r\n" |
| 19205 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19206 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 19207 | MockWrite("GET / HTTP/1.1\r\n" |
| 19208 | "Host: www.example.org\r\n" |
| 19209 | "Connection: Upgrade\r\n" |
| 19210 | "Upgrade: websocket\r\n" |
| 19211 | "Origin: http://www.example.org\r\n" |
| 19212 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19213 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 19214 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 19215 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19216 | |
| 19217 | // The proxy responds to the connect with a 407, using a persistent |
| 19218 | // connection. |
| 19219 | MockRead data_reads[] = { |
| 19220 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19221 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 19222 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 19223 | "Content-Length: 0\r\n" |
| 19224 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19225 | |
| 19226 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19227 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19228 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 19229 | "Upgrade: websocket\r\n" |
| 19230 | "Connection: Upgrade\r\n" |
| 19231 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19232 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19233 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19234 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19235 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19237 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19238 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 19239 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 19240 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19241 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19242 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 19243 | &websocket_stream_create_helper); |
| 19244 | |
| 19245 | { |
| 19246 | TestCompletionCallback callback; |
| 19247 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19248 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19250 | |
| 19251 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19252 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19253 | } |
| 19254 | |
| 19255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19256 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 19257 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19258 | EXPECT_EQ(407, response->headers->response_code()); |
| 19259 | |
| 19260 | { |
| 19261 | TestCompletionCallback callback; |
| 19262 | |
| 19263 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 19264 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19265 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19266 | |
| 19267 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19268 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19269 | } |
| 19270 | |
| 19271 | response = trans->GetResponseInfo(); |
| 19272 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 19273 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19274 | |
| 19275 | EXPECT_EQ(101, response->headers->response_code()); |
| 19276 | |
| 19277 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 19278 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19279 | } |
| 19280 | |
| 19281 | // Verify that proxy headers are not sent to the destination server when |
| 19282 | // establishing a tunnel for an insecure WebSocket connection. |
| 19283 | // This requires the authentication info to be injected into the auth cache |
| 19284 | // due to crbug.com/395064 |
| 19285 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19286 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19287 | HttpRequestInfo request; |
| 19288 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 19289 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19290 | request.traffic_annotation = |
| 19291 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19292 | AddWebSocketHeaders(&request.extra_headers); |
| 19293 | |
| 19294 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 19295 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19296 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 19297 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19298 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19300 | |
| 19301 | MockWrite data_writes[] = { |
| 19302 | // Try to establish a tunnel for the WebSocket connection, with |
| 19303 | // credentials. Because WebSockets have a separate set of socket pools, |
| 19304 | // they cannot and will not use the same TCP/IP connection as the |
| 19305 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19306 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 19307 | "Host: www.example.org:80\r\n" |
| 19308 | "Proxy-Connection: keep-alive\r\n" |
| 19309 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19310 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19311 | MockWrite("GET / HTTP/1.1\r\n" |
| 19312 | "Host: www.example.org\r\n" |
| 19313 | "Connection: Upgrade\r\n" |
| 19314 | "Upgrade: websocket\r\n" |
| 19315 | "Origin: http://www.example.org\r\n" |
| 19316 | "Sec-WebSocket-Version: 13\r\n" |
| 19317 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 19318 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 19319 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19320 | |
| 19321 | MockRead data_reads[] = { |
| 19322 | // HTTP CONNECT with credentials. |
| 19323 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19324 | |
| 19325 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19326 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 19327 | "Upgrade: websocket\r\n" |
| 19328 | "Connection: Upgrade\r\n" |
| 19329 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19330 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19331 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19332 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19333 | |
| 19334 | session->http_auth_cache()->Add( |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame] | 19335 | GURL("http://myproxy:70/"), HttpAuth::AUTH_PROXY, "MyRealm1", |
Matt Menke | be09042 | 2019-10-18 20:25:26 | [diff] [blame] | 19336 | HttpAuth::AUTH_SCHEME_BASIC, NetworkIsolationKey(), |
| 19337 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19338 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 19339 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 19340 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 19341 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19342 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19343 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 19344 | &websocket_stream_create_helper); |
| 19345 | |
| 19346 | TestCompletionCallback callback; |
| 19347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19348 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19350 | |
| 19351 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19352 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19353 | |
| 19354 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19355 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 19356 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19357 | |
| 19358 | EXPECT_EQ(101, response->headers->response_code()); |
| 19359 | |
| 19360 | trans.reset(); |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 19361 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19362 | } |
| 19363 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 19364 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 19365 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 19366 | for (bool secure : {true, false}) { |
| 19367 | SCOPED_TRACE(secure); |
| 19368 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19369 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 19370 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19371 | session_deps_.enable_quic = true; |
| 19372 | |
| 19373 | HttpRequestInfo request; |
| 19374 | request.url = |
| 19375 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 19376 | AddWebSocketHeaders(&request.extra_headers); |
| 19377 | request.traffic_annotation = |
| 19378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19379 | |
| 19380 | TestWebSocketHandshakeStreamCreateHelper |
| 19381 | websocket_handshake_stream_create_helper; |
| 19382 | |
| 19383 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19384 | HttpNetworkTransaction trans(LOW, session.get()); |
| 19385 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 19386 | &websocket_handshake_stream_create_helper); |
| 19387 | |
| 19388 | TestCompletionCallback callback; |
| 19389 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19391 | |
| 19392 | rv = callback.WaitForResult(); |
| 19393 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 19394 | } |
| 19395 | } |
| 19396 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 19397 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 19398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19399 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19400 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19401 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19402 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19403 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19404 | |
| 19405 | HttpRequestInfo request; |
| 19406 | request.method = "POST"; |
| 19407 | request.url = GURL("http://www.foo.com/"); |
| 19408 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19409 | request.traffic_annotation = |
| 19410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19414 | MockWrite data_writes[] = { |
| 19415 | MockWrite("POST / HTTP/1.1\r\n" |
| 19416 | "Host: www.foo.com\r\n" |
| 19417 | "Connection: keep-alive\r\n" |
| 19418 | "Content-Length: 3\r\n\r\n"), |
| 19419 | MockWrite("foo"), |
| 19420 | }; |
| 19421 | |
| 19422 | MockRead data_reads[] = { |
| 19423 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 19424 | MockRead(SYNCHRONOUS, OK), |
| 19425 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19426 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19427 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19428 | |
| 19429 | TestCompletionCallback callback; |
| 19430 | |
| 19431 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19432 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19433 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19434 | |
| 19435 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19436 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19437 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19438 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 19439 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19440 | } |
| 19441 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19442 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19443 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19444 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 19445 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 19446 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19447 | |
| 19448 | HttpRequestInfo request; |
| 19449 | request.method = "POST"; |
| 19450 | request.url = GURL("http://www.foo.com/"); |
| 19451 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19452 | request.traffic_annotation = |
| 19453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19454 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19457 | MockWrite data_writes[] = { |
| 19458 | MockWrite("POST / HTTP/1.1\r\n" |
| 19459 | "Host: www.foo.com\r\n" |
| 19460 | "Connection: keep-alive\r\n" |
| 19461 | "Content-Length: 3\r\n\r\n"), |
| 19462 | MockWrite("foo"), |
| 19463 | }; |
| 19464 | |
| 19465 | MockRead data_reads[] = { |
| 19466 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 19467 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 19468 | MockRead(SYNCHRONOUS, OK), |
| 19469 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19470 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19471 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19472 | |
| 19473 | TestCompletionCallback callback; |
| 19474 | |
| 19475 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19476 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19477 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19478 | |
| 19479 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19480 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19481 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19482 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 19483 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19484 | } |
| 19485 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 19486 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19487 | ChunkedUploadDataStream upload_data_stream(0); |
| 19488 | |
| 19489 | HttpRequestInfo request; |
| 19490 | request.method = "POST"; |
| 19491 | request.url = GURL("http://www.foo.com/"); |
| 19492 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19493 | request.traffic_annotation = |
| 19494 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19495 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 19496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19497 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19498 | // Send headers successfully, but get an error while sending the body. |
| 19499 | MockWrite data_writes[] = { |
| 19500 | MockWrite("POST / HTTP/1.1\r\n" |
| 19501 | "Host: www.foo.com\r\n" |
| 19502 | "Connection: keep-alive\r\n" |
| 19503 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 19504 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 19505 | }; |
| 19506 | |
| 19507 | MockRead data_reads[] = { |
| 19508 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 19509 | MockRead(SYNCHRONOUS, OK), |
| 19510 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19511 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19513 | |
| 19514 | TestCompletionCallback callback; |
| 19515 | |
| 19516 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 19517 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19518 | |
| 19519 | base::RunLoop().RunUntilIdle(); |
| 19520 | upload_data_stream.AppendData("f", 1, false); |
| 19521 | |
| 19522 | base::RunLoop().RunUntilIdle(); |
| 19523 | upload_data_stream.AppendData("oo", 2, true); |
| 19524 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 19525 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19526 | |
| 19527 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 19528 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19529 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19530 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 19531 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 19532 | } |
| 19533 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19534 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 19535 | const std::string& accept_encoding, |
| 19536 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19537 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19538 | bool should_match) { |
| 19539 | HttpRequestInfo request; |
| 19540 | request.method = "GET"; |
| 19541 | request.url = GURL("http://www.foo.com/"); |
| 19542 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 19543 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19544 | request.traffic_annotation = |
| 19545 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19546 | |
| 19547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 19548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19549 | // Send headers successfully, but get an error while sending the body. |
| 19550 | MockWrite data_writes[] = { |
| 19551 | MockWrite("GET / HTTP/1.1\r\n" |
| 19552 | "Host: www.foo.com\r\n" |
| 19553 | "Connection: keep-alive\r\n" |
| 19554 | "Accept-Encoding: "), |
| 19555 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 19556 | }; |
| 19557 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19558 | std::string response_code = "200 OK"; |
| 19559 | std::string extra; |
| 19560 | if (!location.empty()) { |
| 19561 | response_code = "301 Redirect\r\nLocation: "; |
| 19562 | response_code.append(location); |
| 19563 | } |
| 19564 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19565 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19566 | MockRead("HTTP/1.0 "), |
| 19567 | MockRead(response_code.data()), |
| 19568 | MockRead("\r\nContent-Encoding: "), |
| 19569 | MockRead(content_encoding.data()), |
| 19570 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19571 | MockRead(SYNCHRONOUS, OK), |
| 19572 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 19573 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19574 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 19575 | |
| 19576 | TestCompletionCallback callback; |
| 19577 | |
| 19578 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19579 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19580 | |
| 19581 | rv = callback.WaitForResult(); |
| 19582 | if (should_match) { |
| 19583 | EXPECT_THAT(rv, IsOk()); |
| 19584 | } else { |
| 19585 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 19586 | } |
| 19587 | } |
| 19588 | |
| 19589 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19590 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19591 | } |
| 19592 | |
| 19593 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19594 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 19595 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19596 | } |
| 19597 | |
| 19598 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 19599 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 19600 | "", false); |
| 19601 | } |
| 19602 | |
| 19603 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 19604 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 19605 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 19606 | } |
| 19607 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19608 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 19609 | ProxyConfig proxy_config; |
| 19610 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 19611 | proxy_config.set_pac_mandatory(true); |
| 19612 | MockAsyncProxyResolver resolver; |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19613 | session_deps_.proxy_resolution_service.reset( |
| 19614 | new ConfiguredProxyResolutionService( |
| 19615 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 19616 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 19617 | std::make_unique<FailingProxyResolverFactory>(), nullptr, |
| 19618 | /*quick_check_enabled=*/true)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19619 | |
| 19620 | HttpRequestInfo request; |
| 19621 | request.method = "GET"; |
| 19622 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19623 | request.traffic_annotation = |
| 19624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19625 | |
| 19626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19628 | |
| 19629 | TestCompletionCallback callback; |
| 19630 | |
| 19631 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19633 | EXPECT_THAT(callback.WaitForResult(), |
| 19634 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 19635 | } |
| 19636 | |
| 19637 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 19638 | ProxyConfig proxy_config; |
| 19639 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 19640 | proxy_config.set_pac_mandatory(true); |
| 19641 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 19642 | new MockAsyncProxyResolverFactory(false); |
| 19643 | MockAsyncProxyResolver resolver; |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19644 | session_deps_.proxy_resolution_service.reset( |
| 19645 | new ConfiguredProxyResolutionService( |
| 19646 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 19647 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Eric Roman | 3be01ba | 2020-04-03 21:37:09 | [diff] [blame] | 19648 | base::WrapUnique(proxy_resolver_factory), nullptr, |
| 19649 | /*quick_check_enabled=*/true)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19650 | HttpRequestInfo request; |
| 19651 | request.method = "GET"; |
| 19652 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19653 | request.traffic_annotation = |
| 19654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19655 | |
| 19656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19657 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19658 | |
| 19659 | TestCompletionCallback callback; |
| 19660 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19662 | |
| 19663 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 19664 | ERR_FAILED, &resolver); |
| 19665 | EXPECT_THAT(callback.WaitForResult(), |
| 19666 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 19667 | } |
| 19668 | |
| 19669 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 19670 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19671 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 19672 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19673 | session_deps_.enable_quic = false; |
| 19674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19675 | |
| 19676 | HttpRequestInfo request; |
| 19677 | request.method = "GET"; |
| 19678 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 19679 | request.traffic_annotation = |
| 19680 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 19681 | |
| 19682 | TestCompletionCallback callback; |
| 19683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19684 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 19685 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19686 | |
| 19687 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 19688 | } |
| 19689 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19690 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19691 | // Reporting tests |
| 19692 | |
| 19693 | #if BUILDFLAG(ENABLE_REPORTING) |
| 19694 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 19695 | protected: |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 19696 | HttpNetworkTransactionReportingTest() { |
| 19697 | feature_list_.InitAndEnableFeature( |
| 19698 | features::kPartitionNelAndReportingByNetworkIsolationKey); |
| 19699 | } |
| 19700 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19701 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19702 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19703 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 19704 | &clock_, &tick_clock_, ReportingPolicy()); |
| 19705 | test_reporting_context_ = test_reporting_context.get(); |
| 19706 | session_deps_.reporting_service = |
| 19707 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 19708 | } |
| 19709 | |
| 19710 | TestReportingContext* reporting_context() const { |
| 19711 | return test_reporting_context_; |
| 19712 | } |
| 19713 | |
| 19714 | void clear_reporting_service() { |
| 19715 | session_deps_.reporting_service.reset(); |
| 19716 | test_reporting_context_ = nullptr; |
| 19717 | } |
| 19718 | |
| 19719 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19720 | void RequestPolicy(CertStatus cert_status = 0) { |
| 19721 | HttpRequestInfo request; |
| 19722 | request.method = "GET"; |
| 19723 | request.url = GURL(url_); |
| 19724 | request.traffic_annotation = |
| 19725 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 19726 | request.network_isolation_key = kNetworkIsolationKey; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19727 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19728 | MockWrite data_writes[] = { |
| 19729 | MockWrite("GET / HTTP/1.1\r\n" |
| 19730 | "Host: www.example.org\r\n" |
| 19731 | "Connection: keep-alive\r\n\r\n"), |
| 19732 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19733 | MockRead data_reads[] = { |
| 19734 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19735 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 19736 | "\"endpoints\": [{\"url\": " |
| 19737 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 19738 | MockRead("\r\n"), |
| 19739 | MockRead("hello world"), |
| 19740 | MockRead(SYNCHRONOUS, OK), |
| 19741 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19742 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19743 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19744 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19745 | |
| 19746 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19747 | if (request.url.SchemeIsCryptographic()) { |
| 19748 | ssl.ssl_info.cert = |
| 19749 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19750 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19751 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19753 | } |
| 19754 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19755 | TestCompletionCallback callback; |
| 19756 | auto session = CreateSession(&session_deps_); |
| 19757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19758 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19759 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19760 | } |
| 19761 | |
| 19762 | protected: |
| 19763 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19764 | |
| 19765 | private: |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 19766 | base::test::ScopedFeatureList feature_list_; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19767 | TestReportingContext* test_reporting_context_; |
| 19768 | }; |
| 19769 | |
| 19770 | TEST_F(HttpNetworkTransactionReportingTest, |
| 19771 | DontProcessReportToHeaderNoService) { |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19772 | clear_reporting_service(); |
| 19773 | RequestPolicy(); |
Lily Chen | 9364a4c | 2020-06-25 16:07:52 | [diff] [blame] | 19774 | // No crash. |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19775 | } |
| 19776 | |
| 19777 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19778 | url_ = "http://www.example.org/"; |
| 19779 | RequestPolicy(); |
Lily Chen | 9364a4c | 2020-06-25 16:07:52 | [diff] [blame] | 19780 | EXPECT_EQ(0u, reporting_context()->cache()->GetEndpointCount()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19781 | } |
| 19782 | |
| 19783 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 19784 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 19785 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 19786 | const ReportingEndpoint endpoint = |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 19787 | reporting_context()->cache()->GetEndpointForTesting( |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 19788 | ReportingEndpointGroupKey( |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 19789 | kNetworkIsolationKey, |
Lily Chen | ad5dd080 | 2020-03-10 21:58:09 | [diff] [blame] | 19790 | url::Origin::Create(GURL("https://www.example.org/")), "nel"), |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 19791 | GURL("https://www.example.org/upload/")); |
| 19792 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19793 | } |
| 19794 | |
| 19795 | TEST_F(HttpNetworkTransactionReportingTest, |
| 19796 | DontProcessReportToHeaderInvalidHttps) { |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19797 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 19798 | RequestPolicy(cert_status); |
Lily Chen | 9364a4c | 2020-06-25 16:07:52 | [diff] [blame] | 19799 | EXPECT_EQ(0u, reporting_context()->cache()->GetEndpointCount()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 19800 | } |
| 19801 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19802 | |
| 19803 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19804 | // Network Error Logging tests |
| 19805 | |
| 19806 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19807 | namespace { |
| 19808 | |
| 19809 | const char kUserAgent[] = "Mozilla/1.0"; |
| 19810 | const char kReferrer[] = "https://www.referrer.org/"; |
| 19811 | |
| 19812 | } // namespace |
| 19813 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19814 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 19815 | : public HttpNetworkTransactionTest { |
| 19816 | protected: |
| 19817 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19818 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19819 | auto network_error_logging_service = |
| 19820 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 19821 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 19822 | session_deps_.network_error_logging_service = |
| 19823 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19824 | |
| 19825 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 19826 | extra_headers_.SetHeader("Referer", kReferrer); |
| 19827 | |
| 19828 | request_.method = "GET"; |
| 19829 | request_.url = GURL(url_); |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 19830 | request_.network_isolation_key = kNetworkIsolationKey; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19831 | request_.extra_headers = extra_headers_; |
| 19832 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 19833 | request_.traffic_annotation = |
| 19834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19835 | } |
| 19836 | |
| 19837 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 19838 | return test_network_error_logging_service_; |
| 19839 | } |
| 19840 | |
| 19841 | void clear_network_error_logging_service() { |
| 19842 | session_deps_.network_error_logging_service.reset(); |
| 19843 | test_network_error_logging_service_ = nullptr; |
| 19844 | } |
| 19845 | |
| 19846 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19847 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19848 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19849 | MockWrite data_writes[] = { |
| 19850 | MockWrite("GET / HTTP/1.1\r\n" |
| 19851 | "Host: www.example.org\r\n" |
| 19852 | "Connection: keep-alive\r\n"), |
| 19853 | MockWrite(ASYNC, extra_header_string.data(), |
| 19854 | extra_header_string.size()), |
| 19855 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19856 | MockRead data_reads[] = { |
| 19857 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19858 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 19859 | MockRead("\r\n"), |
| 19860 | MockRead("hello world"), |
| 19861 | MockRead(SYNCHRONOUS, OK), |
| 19862 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19863 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19864 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19865 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19866 | |
| 19867 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19868 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19869 | ssl.ssl_info.cert = |
| 19870 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19871 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19872 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19874 | } |
| 19875 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19876 | TestCompletionCallback callback; |
| 19877 | auto session = CreateSession(&session_deps_); |
| 19878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19879 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 19880 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19881 | |
| 19882 | std::string response_data; |
| 19883 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 19884 | EXPECT_EQ("hello world", response_data); |
| 19885 | } |
| 19886 | |
| 19887 | void CheckReport(size_t index, |
| 19888 | int status_code, |
| 19889 | int error_type, |
| 19890 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 19891 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 19892 | |
| 19893 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19894 | network_error_logging_service()->errors()[index]; |
| 19895 | EXPECT_EQ(url_, error.uri); |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 19896 | EXPECT_EQ(kNetworkIsolationKey, error.network_isolation_key); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19897 | EXPECT_EQ(kReferrer, error.referrer); |
| 19898 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 19899 | EXPECT_EQ(server_ip, error.server_ip); |
| 19900 | EXPECT_EQ("http/1.1", error.protocol); |
| 19901 | EXPECT_EQ("GET", error.method); |
| 19902 | EXPECT_EQ(status_code, error.status_code); |
| 19903 | EXPECT_EQ(error_type, error.type); |
| 19904 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19905 | } |
| 19906 | |
| 19907 | protected: |
| 19908 | std::string url_ = "https://www.example.org/"; |
| 19909 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19910 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19911 | HttpRequestHeaders extra_headers_; |
| 19912 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19913 | |
| 19914 | private: |
| 19915 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 19916 | }; |
| 19917 | |
| 19918 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19919 | DontProcessNelHeaderNoService) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19920 | clear_network_error_logging_service(); |
| 19921 | RequestPolicy(); |
Lily Chen | a9e9d6cb | 2020-06-25 17:34:49 | [diff] [blame] | 19922 | // No crash. |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19923 | } |
| 19924 | |
| 19925 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19926 | DontProcessNelHeaderHttp) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19927 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19928 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19929 | RequestPolicy(); |
Lily Chen | a9e9d6cb | 2020-06-25 17:34:49 | [diff] [blame] | 19930 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19931 | } |
| 19932 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19933 | // Don't set NEL policies received on a proxied connection. |
| 19934 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19935 | DontProcessNelHeaderProxy) { |
| 19936 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 19937 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19938 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 19939 | RecordingBoundTestNetLog log; |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19940 | session_deps_.net_log = log.bound().net_log(); |
| 19941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19942 | |
| 19943 | HttpRequestInfo request; |
| 19944 | request.method = "GET"; |
| 19945 | request.url = GURL("https://www.example.org/"); |
| 19946 | request.traffic_annotation = |
| 19947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19948 | |
| 19949 | // Since we have proxy, should try to establish tunnel. |
| 19950 | MockWrite data_writes1[] = { |
| 19951 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19952 | "Host: www.example.org:443\r\n" |
| 19953 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19954 | |
| 19955 | MockWrite("GET / HTTP/1.1\r\n" |
| 19956 | "Host: www.example.org\r\n" |
| 19957 | "Connection: keep-alive\r\n\r\n"), |
| 19958 | }; |
| 19959 | |
| 19960 | MockRead data_reads1[] = { |
| 19961 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19962 | |
| 19963 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19964 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 19965 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19966 | MockRead("Content-Length: 100\r\n\r\n"), |
| 19967 | MockRead(SYNCHRONOUS, OK), |
| 19968 | }; |
| 19969 | |
| 19970 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19971 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19972 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19973 | ssl.ssl_info.cert = |
| 19974 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19975 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 19976 | ssl.ssl_info.cert_status = 0; |
| 19977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19978 | |
| 19979 | TestCompletionCallback callback1; |
| 19980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19981 | |
| 19982 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 19983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19984 | |
| 19985 | rv = callback1.WaitForResult(); |
| 19986 | EXPECT_THAT(rv, IsOk()); |
| 19987 | |
| 19988 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 19989 | ASSERT_TRUE(response); |
| 19990 | EXPECT_EQ(200, response->headers->response_code()); |
| 19991 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 19992 | |
| 19993 | // No NEL header was set. |
| 19994 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 19995 | } |
| 19996 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19997 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 19998 | RequestPolicy(); |
| 19999 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 20000 | const auto& header = network_error_logging_service()->headers()[0]; |
Matt Menke | f437a87e | 2020-10-22 23:22:24 | [diff] [blame] | 20001 | EXPECT_EQ(kNetworkIsolationKey, header.network_isolation_key); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 20002 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 20003 | header.origin); |
| 20004 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 20005 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 20006 | } |
| 20007 | |
| 20008 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20009 | DontProcessNelHeaderInvalidHttps) { |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20010 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 20011 | RequestPolicy(cert_status); |
Lily Chen | a9e9d6cb | 2020-06-25 17:34:49 | [diff] [blame] | 20012 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 20013 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20014 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20015 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20016 | RequestPolicy(); |
| 20017 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20018 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20019 | } |
| 20020 | |
| 20021 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20022 | CreateReportErrorAfterStart) { |
| 20023 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20024 | auto trans = |
| 20025 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20026 | |
| 20027 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 20028 | StaticSocketDataProvider data; |
| 20029 | data.set_connect_data(mock_connect); |
| 20030 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20031 | |
| 20032 | TestCompletionCallback callback; |
| 20033 | |
| 20034 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20035 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 20036 | |
| 20037 | trans.reset(); |
| 20038 | |
| 20039 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20040 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 20041 | IPAddress() /* server_ip */); |
| 20042 | } |
| 20043 | |
| 20044 | // Same as above except the error is ASYNC |
| 20045 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20046 | CreateReportErrorAfterStartAsync) { |
| 20047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20048 | auto trans = |
| 20049 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20050 | |
| 20051 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 20052 | StaticSocketDataProvider data; |
| 20053 | data.set_connect_data(mock_connect); |
| 20054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20055 | |
| 20056 | TestCompletionCallback callback; |
| 20057 | |
| 20058 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20059 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 20060 | |
| 20061 | trans.reset(); |
| 20062 | |
| 20063 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20064 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 20065 | IPAddress() /* server_ip */); |
| 20066 | } |
| 20067 | |
| 20068 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20069 | CreateReportReadBodyError) { |
| 20070 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 20071 | MockWrite data_writes[] = { |
| 20072 | MockWrite("GET / HTTP/1.1\r\n" |
| 20073 | "Host: www.example.org\r\n" |
| 20074 | "Connection: keep-alive\r\n"), |
| 20075 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20076 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 20077 | MockRead data_reads[] = { |
| 20078 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 20079 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 20080 | MockRead("hello world"), |
| 20081 | MockRead(SYNCHRONOUS, OK), |
| 20082 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20083 | |
| 20084 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 20085 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 20086 | |
| 20087 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20089 | |
| 20090 | // Log start time |
| 20091 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 20092 | |
| 20093 | TestCompletionCallback callback; |
| 20094 | auto session = CreateSession(&session_deps_); |
| 20095 | auto trans = |
| 20096 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20097 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20098 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20099 | |
| 20100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20101 | ASSERT_TRUE(response); |
| 20102 | |
| 20103 | EXPECT_TRUE(response->headers); |
| 20104 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 20105 | |
| 20106 | std::string response_data; |
| 20107 | rv = ReadTransaction(trans.get(), &response_data); |
| 20108 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 20109 | |
| 20110 | trans.reset(); |
| 20111 | |
| 20112 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20113 | |
| 20114 | CheckReport(0 /* index */, 200 /* status_code */, |
| 20115 | ERR_CONTENT_LENGTH_MISMATCH); |
| 20116 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20117 | network_error_logging_service()->errors()[0]; |
| 20118 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 20119 | } |
| 20120 | |
| 20121 | // Same as above except the final read is ASYNC. |
| 20122 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20123 | CreateReportReadBodyErrorAsync) { |
| 20124 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 20125 | MockWrite data_writes[] = { |
| 20126 | MockWrite("GET / HTTP/1.1\r\n" |
| 20127 | "Host: www.example.org\r\n" |
| 20128 | "Connection: keep-alive\r\n"), |
| 20129 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20130 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 20131 | MockRead data_reads[] = { |
| 20132 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 20133 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 20134 | MockRead("hello world"), |
| 20135 | MockRead(ASYNC, OK), |
| 20136 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20137 | |
| 20138 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 20139 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 20140 | |
| 20141 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20143 | |
| 20144 | // Log start time |
| 20145 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 20146 | |
| 20147 | TestCompletionCallback callback; |
| 20148 | auto session = CreateSession(&session_deps_); |
| 20149 | auto trans = |
| 20150 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20151 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20152 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20153 | |
| 20154 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20155 | ASSERT_TRUE(response); |
| 20156 | |
| 20157 | EXPECT_TRUE(response->headers); |
| 20158 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 20159 | |
| 20160 | std::string response_data; |
| 20161 | rv = ReadTransaction(trans.get(), &response_data); |
| 20162 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 20163 | |
| 20164 | trans.reset(); |
| 20165 | |
| 20166 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20167 | |
| 20168 | CheckReport(0 /* index */, 200 /* status_code */, |
| 20169 | ERR_CONTENT_LENGTH_MISMATCH); |
| 20170 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20171 | network_error_logging_service()->errors()[0]; |
| 20172 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 20173 | } |
| 20174 | |
| 20175 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20176 | CreateReportRestartWithAuth) { |
| 20177 | std::string extra_header_string = extra_headers_.ToString(); |
| 20178 | static const base::TimeDelta kSleepDuration = |
| 20179 | base::TimeDelta::FromMilliseconds(10); |
| 20180 | |
| 20181 | MockWrite data_writes1[] = { |
| 20182 | MockWrite("GET / HTTP/1.1\r\n" |
| 20183 | "Host: www.example.org\r\n" |
| 20184 | "Connection: keep-alive\r\n"), |
| 20185 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20186 | }; |
| 20187 | |
| 20188 | MockRead data_reads1[] = { |
| 20189 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 20190 | // Give a couple authenticate options (only the middle one is actually |
| 20191 | // supported). |
| 20192 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 20193 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 20194 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 20195 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 20196 | // Large content-length -- won't matter, as connection will be reset. |
| 20197 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 20198 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 20199 | }; |
| 20200 | |
| 20201 | // After calling trans->RestartWithAuth(), this is the request we should |
| 20202 | // be issuing -- the final header line contains the credentials. |
| 20203 | MockWrite data_writes2[] = { |
| 20204 | MockWrite("GET / HTTP/1.1\r\n" |
| 20205 | "Host: www.example.org\r\n" |
| 20206 | "Connection: keep-alive\r\n" |
| 20207 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 20208 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20209 | }; |
| 20210 | |
| 20211 | // Lastly, the server responds with the actual content. |
| 20212 | MockRead data_reads2[] = { |
| 20213 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 20214 | MockRead("hello world"), |
| 20215 | MockRead(SYNCHRONOUS, OK), |
| 20216 | }; |
| 20217 | |
| 20218 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20219 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 20220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20221 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20222 | |
| 20223 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20225 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20227 | |
| 20228 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 20229 | base::TimeTicks restart_time; |
| 20230 | |
| 20231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20232 | auto trans = |
| 20233 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20234 | |
| 20235 | TestCompletionCallback callback1; |
| 20236 | |
| 20237 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20238 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20239 | |
| 20240 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20241 | |
| 20242 | TestCompletionCallback callback2; |
| 20243 | |
| 20244 | // Wait 10 ms then restart with auth |
| 20245 | FastForwardBy(kSleepDuration); |
| 20246 | restart_time = base::TimeTicks::Now(); |
| 20247 | rv = |
| 20248 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 20249 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20250 | |
| 20251 | std::string response_data; |
| 20252 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20253 | EXPECT_EQ("hello world", response_data); |
| 20254 | |
| 20255 | trans.reset(); |
| 20256 | |
| 20257 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 20258 | // retry. Note that we don't report the error draining the body, as the first |
| 20259 | // request already generated a report for the auth challenge. |
| 20260 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 20261 | |
| 20262 | // Check error report contents |
| 20263 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 20264 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 20265 | |
| 20266 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 20267 | network_error_logging_service()->errors()[0]; |
| 20268 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 20269 | network_error_logging_service()->errors()[1]; |
| 20270 | |
| 20271 | // Sanity-check elapsed time values |
| 20272 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 20273 | // Check that the start time is refreshed when restarting with auth. |
| 20274 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 20275 | } |
| 20276 | |
| 20277 | // Same as above, except draining the body before restarting fails |
| 20278 | // asynchronously. |
| 20279 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20280 | CreateReportRestartWithAuthAsync) { |
| 20281 | std::string extra_header_string = extra_headers_.ToString(); |
| 20282 | static const base::TimeDelta kSleepDuration = |
| 20283 | base::TimeDelta::FromMilliseconds(10); |
| 20284 | |
| 20285 | MockWrite data_writes1[] = { |
| 20286 | MockWrite("GET / HTTP/1.1\r\n" |
| 20287 | "Host: www.example.org\r\n" |
| 20288 | "Connection: keep-alive\r\n"), |
| 20289 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20290 | }; |
| 20291 | |
| 20292 | MockRead data_reads1[] = { |
| 20293 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 20294 | // Give a couple authenticate options (only the middle one is actually |
| 20295 | // supported). |
| 20296 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 20297 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 20298 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 20299 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 20300 | // Large content-length -- won't matter, as connection will be reset. |
| 20301 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 20302 | MockRead(ASYNC, ERR_FAILED), |
| 20303 | }; |
| 20304 | |
| 20305 | // After calling trans->RestartWithAuth(), this is the request we should |
| 20306 | // be issuing -- the final header line contains the credentials. |
| 20307 | MockWrite data_writes2[] = { |
| 20308 | MockWrite("GET / HTTP/1.1\r\n" |
| 20309 | "Host: www.example.org\r\n" |
| 20310 | "Connection: keep-alive\r\n" |
| 20311 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 20312 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20313 | }; |
| 20314 | |
| 20315 | // Lastly, the server responds with the actual content. |
| 20316 | MockRead data_reads2[] = { |
| 20317 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 20318 | MockRead("hello world"), |
| 20319 | MockRead(SYNCHRONOUS, OK), |
| 20320 | }; |
| 20321 | |
| 20322 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20323 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 20324 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20325 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20326 | |
| 20327 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20328 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20329 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20331 | |
| 20332 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 20333 | base::TimeTicks restart_time; |
| 20334 | |
| 20335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20336 | auto trans = |
| 20337 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20338 | |
| 20339 | TestCompletionCallback callback1; |
| 20340 | |
| 20341 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20342 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20343 | |
| 20344 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20345 | |
| 20346 | TestCompletionCallback callback2; |
| 20347 | |
| 20348 | // Wait 10 ms then restart with auth |
| 20349 | FastForwardBy(kSleepDuration); |
| 20350 | restart_time = base::TimeTicks::Now(); |
| 20351 | rv = |
| 20352 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 20353 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20354 | |
| 20355 | std::string response_data; |
| 20356 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20357 | EXPECT_EQ("hello world", response_data); |
| 20358 | |
| 20359 | trans.reset(); |
| 20360 | |
| 20361 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 20362 | // retry. Note that we don't report the error draining the body, as the first |
| 20363 | // request already generated a report for the auth challenge. |
| 20364 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 20365 | |
| 20366 | // Check error report contents |
| 20367 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 20368 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 20369 | |
| 20370 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 20371 | network_error_logging_service()->errors()[0]; |
| 20372 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 20373 | network_error_logging_service()->errors()[1]; |
| 20374 | |
| 20375 | // Sanity-check elapsed time values |
| 20376 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 20377 | // Check that the start time is refreshed when restarting with auth. |
| 20378 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 20379 | } |
| 20380 | |
| 20381 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20382 | CreateReportRetryKeepAliveConnectionReset) { |
| 20383 | std::string extra_header_string = extra_headers_.ToString(); |
| 20384 | MockWrite data_writes1[] = { |
| 20385 | MockWrite("GET / HTTP/1.1\r\n" |
| 20386 | "Host: www.example.org\r\n" |
| 20387 | "Connection: keep-alive\r\n"), |
| 20388 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20389 | MockWrite("GET / HTTP/1.1\r\n" |
| 20390 | "Host: www.example.org\r\n" |
| 20391 | "Connection: keep-alive\r\n"), |
| 20392 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20393 | }; |
| 20394 | |
| 20395 | MockRead data_reads1[] = { |
| 20396 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20397 | MockRead("hello"), |
| 20398 | // Connection is reset |
| 20399 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 20400 | }; |
| 20401 | |
| 20402 | // Successful retry |
| 20403 | MockRead data_reads2[] = { |
| 20404 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20405 | MockRead("world"), |
| 20406 | MockRead(ASYNC, OK), |
| 20407 | }; |
| 20408 | |
| 20409 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20410 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 20411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20412 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20413 | |
| 20414 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20416 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20417 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20418 | |
| 20419 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20420 | auto trans1 = |
| 20421 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20422 | |
| 20423 | TestCompletionCallback callback1; |
| 20424 | |
| 20425 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20426 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20427 | |
| 20428 | std::string response_data; |
| 20429 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 20430 | EXPECT_EQ("hello", response_data); |
| 20431 | |
| 20432 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20433 | |
| 20434 | auto trans2 = |
| 20435 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20436 | |
| 20437 | TestCompletionCallback callback2; |
| 20438 | |
| 20439 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 20440 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20441 | |
| 20442 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 20443 | EXPECT_EQ("world", response_data); |
| 20444 | |
| 20445 | trans1.reset(); |
| 20446 | trans2.reset(); |
| 20447 | |
| 20448 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 20449 | // the second request, then an OK report from the successful retry. |
| 20450 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 20451 | |
| 20452 | // Check error report contents |
| 20453 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20454 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 20455 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 20456 | } |
| 20457 | |
| 20458 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20459 | CreateReportRetryKeepAlive408) { |
| 20460 | std::string extra_header_string = extra_headers_.ToString(); |
| 20461 | MockWrite data_writes1[] = { |
| 20462 | MockWrite("GET / HTTP/1.1\r\n" |
| 20463 | "Host: www.example.org\r\n" |
| 20464 | "Connection: keep-alive\r\n"), |
| 20465 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20466 | MockWrite("GET / HTTP/1.1\r\n" |
| 20467 | "Host: www.example.org\r\n" |
| 20468 | "Connection: keep-alive\r\n"), |
| 20469 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20470 | }; |
| 20471 | |
| 20472 | MockRead data_reads1[] = { |
| 20473 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20474 | MockRead("hello"), |
| 20475 | // 408 Request Timeout |
| 20476 | MockRead(SYNCHRONOUS, |
| 20477 | "HTTP/1.1 408 Request Timeout\r\n" |
| 20478 | "Connection: Keep-Alive\r\n" |
| 20479 | "Content-Length: 6\r\n\r\n" |
| 20480 | "Pickle"), |
| 20481 | }; |
| 20482 | |
| 20483 | // Successful retry |
| 20484 | MockRead data_reads2[] = { |
| 20485 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 20486 | MockRead("world"), |
| 20487 | MockRead(ASYNC, OK), |
| 20488 | }; |
| 20489 | |
| 20490 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20491 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 20492 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20493 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20494 | |
| 20495 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 20496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20497 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20499 | |
| 20500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20501 | auto trans1 = |
| 20502 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20503 | |
| 20504 | TestCompletionCallback callback1; |
| 20505 | |
| 20506 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 20507 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20508 | |
| 20509 | std::string response_data; |
| 20510 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 20511 | EXPECT_EQ("hello", response_data); |
| 20512 | |
| 20513 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20514 | |
| 20515 | auto trans2 = |
| 20516 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20517 | |
| 20518 | TestCompletionCallback callback2; |
| 20519 | |
| 20520 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 20521 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20522 | |
| 20523 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 20524 | EXPECT_EQ("world", response_data); |
| 20525 | |
| 20526 | trans1.reset(); |
| 20527 | trans2.reset(); |
| 20528 | |
| 20529 | // One 200 report from first request, then a 408 report from |
| 20530 | // the second request, then a 200 report from the successful retry. |
| 20531 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 20532 | |
| 20533 | // Check error report contents |
| 20534 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20535 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 20536 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 20537 | } |
| 20538 | |
| 20539 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20540 | CreateReportRetry421WithoutConnectionPooling) { |
| 20541 | // Two hosts resolve to the same IP address. |
| 20542 | const std::string ip_addr = "1.2.3.4"; |
| 20543 | IPAddress ip; |
| 20544 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 20545 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 20546 | |
| 20547 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 20548 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 20549 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 20550 | |
| 20551 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20552 | |
| 20553 | // Two requests on the first connection. |
| 20554 | spdy::SpdySerializedFrame req1( |
| 20555 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 20556 | spdy_util_.UpdateWithStreamDestruction(1); |
| 20557 | spdy::SpdySerializedFrame req2( |
| 20558 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 20559 | spdy::SpdySerializedFrame rst( |
| 20560 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 20561 | MockWrite writes1[] = { |
| 20562 | CreateMockWrite(req1, 0), |
| 20563 | CreateMockWrite(req2, 3), |
| 20564 | CreateMockWrite(rst, 6), |
| 20565 | }; |
| 20566 | |
| 20567 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 20568 | spdy::SpdySerializedFrame resp1( |
| 20569 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 20570 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 20571 | spdy::Http2HeaderBlock response_headers; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20572 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 20573 | spdy::SpdySerializedFrame resp2( |
| 20574 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 20575 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 20576 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 20577 | |
| 20578 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 20579 | SequencedSocketData data1(connect1, reads1, writes1); |
| 20580 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20581 | |
| 20582 | AddSSLSocketData(); |
| 20583 | |
| 20584 | // Retry the second request on a second connection. |
| 20585 | SpdyTestUtil spdy_util2; |
| 20586 | spdy::SpdySerializedFrame req3( |
| 20587 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 20588 | MockWrite writes2[] = { |
| 20589 | CreateMockWrite(req3, 0), |
| 20590 | }; |
| 20591 | |
| 20592 | spdy::SpdySerializedFrame resp3( |
| 20593 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 20594 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 20595 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 20596 | MockRead(ASYNC, 0, 3)}; |
| 20597 | |
| 20598 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 20599 | SequencedSocketData data2(connect2, reads2, writes2); |
| 20600 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20601 | |
| 20602 | AddSSLSocketData(); |
| 20603 | |
| 20604 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 20605 | int rv = session_deps_.host_resolver->LoadIntoCache( |
Matt Menke | cd43923 | 2019-11-05 15:15:33 | [diff] [blame] | 20606 | HostPortPair("mail.example.com", 443), NetworkIsolationKey(), |
| 20607 | base::nullopt); |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 20608 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20609 | |
| 20610 | HttpRequestInfo request1; |
| 20611 | request1.method = "GET"; |
| 20612 | request1.url = GURL("https://www.example.org/"); |
| 20613 | request1.load_flags = 0; |
| 20614 | request1.traffic_annotation = |
| 20615 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20616 | auto trans1 = |
| 20617 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20618 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 20619 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20620 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 20621 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20622 | |
| 20623 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 20624 | ASSERT_TRUE(response); |
| 20625 | ASSERT_TRUE(response->headers); |
| 20626 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 20627 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 20628 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 20629 | std::string response_data; |
| 20630 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 20631 | EXPECT_EQ("hello!", response_data); |
| 20632 | |
| 20633 | trans1.reset(); |
| 20634 | |
| 20635 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20636 | |
| 20637 | HttpRequestInfo request2; |
| 20638 | request2.method = "GET"; |
| 20639 | request2.url = GURL("https://mail.example.org/"); |
| 20640 | request2.load_flags = 0; |
| 20641 | request2.traffic_annotation = |
| 20642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20643 | auto trans2 = |
| 20644 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20645 | |
Matt Mueller | d9342e3a | 2019-11-26 01:41:14 | [diff] [blame] | 20646 | RecordingBoundTestNetLog log; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20647 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 20648 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20649 | |
| 20650 | response = trans2->GetResponseInfo(); |
| 20651 | ASSERT_TRUE(response); |
| 20652 | ASSERT_TRUE(response->headers); |
| 20653 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 20654 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 20655 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 20656 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 20657 | EXPECT_EQ("hello!", response_data); |
| 20658 | |
| 20659 | trans2.reset(); |
| 20660 | |
| 20661 | // One 200 report from the first request, then a 421 report from the |
| 20662 | // second request, then a 200 report from the successful retry. |
| 20663 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 20664 | |
| 20665 | // Check error report contents |
| 20666 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 20667 | network_error_logging_service()->errors()[0]; |
| 20668 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 20669 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 20670 | EXPECT_EQ("", error1.user_agent); |
| 20671 | EXPECT_EQ(ip, error1.server_ip); |
| 20672 | EXPECT_EQ("h2", error1.protocol); |
| 20673 | EXPECT_EQ("GET", error1.method); |
| 20674 | EXPECT_EQ(200, error1.status_code); |
| 20675 | EXPECT_EQ(OK, error1.type); |
| 20676 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 20677 | |
| 20678 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 20679 | network_error_logging_service()->errors()[1]; |
| 20680 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 20681 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 20682 | EXPECT_EQ("", error2.user_agent); |
| 20683 | EXPECT_EQ(ip, error2.server_ip); |
| 20684 | EXPECT_EQ("h2", error2.protocol); |
| 20685 | EXPECT_EQ("GET", error2.method); |
| 20686 | EXPECT_EQ(421, error2.status_code); |
| 20687 | EXPECT_EQ(OK, error2.type); |
| 20688 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 20689 | |
| 20690 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 20691 | network_error_logging_service()->errors()[2]; |
| 20692 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 20693 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 20694 | EXPECT_EQ("", error3.user_agent); |
| 20695 | EXPECT_EQ(ip, error3.server_ip); |
| 20696 | EXPECT_EQ("h2", error3.protocol); |
| 20697 | EXPECT_EQ("GET", error3.method); |
| 20698 | EXPECT_EQ(200, error3.status_code); |
| 20699 | EXPECT_EQ(OK, error3.type); |
| 20700 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20701 | } |
| 20702 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 20703 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20704 | CreateReportCancelAfterStart) { |
| 20705 | StaticSocketDataProvider data; |
| 20706 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 20707 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20708 | |
| 20709 | TestCompletionCallback callback; |
| 20710 | auto session = CreateSession(&session_deps_); |
| 20711 | auto trans = |
| 20712 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20713 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20714 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 20715 | |
| 20716 | // Cancel after start. |
| 20717 | trans.reset(); |
| 20718 | |
| 20719 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20720 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 20721 | IPAddress() /* server_ip */); |
| 20722 | } |
| 20723 | |
| 20724 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20725 | CreateReportCancelBeforeReadingBody) { |
| 20726 | std::string extra_header_string = extra_headers_.ToString(); |
| 20727 | MockWrite data_writes[] = { |
| 20728 | MockWrite("GET / HTTP/1.1\r\n" |
| 20729 | "Host: www.example.org\r\n" |
| 20730 | "Connection: keep-alive\r\n"), |
| 20731 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20732 | }; |
| 20733 | MockRead data_reads[] = { |
| 20734 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 20735 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 20736 | }; |
| 20737 | |
| 20738 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20739 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20740 | |
| 20741 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20743 | |
| 20744 | TestCompletionCallback callback; |
| 20745 | auto session = CreateSession(&session_deps_); |
| 20746 | auto trans = |
| 20747 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20748 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20749 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20750 | |
| 20751 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20752 | ASSERT_TRUE(response); |
| 20753 | |
| 20754 | EXPECT_TRUE(response->headers); |
| 20755 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 20756 | |
| 20757 | // Cancel before reading the body. |
| 20758 | trans.reset(); |
| 20759 | |
| 20760 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20761 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 20762 | } |
| 20763 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20764 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20765 | RequestPolicy(); |
| 20766 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 20767 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20768 | |
| 20769 | // Make HTTP request |
| 20770 | std::string extra_header_string = extra_headers_.ToString(); |
| 20771 | MockRead data_reads[] = { |
| 20772 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 20773 | MockRead("hello world"), |
| 20774 | MockRead(SYNCHRONOUS, OK), |
| 20775 | }; |
| 20776 | MockWrite data_writes[] = { |
| 20777 | MockWrite("GET / HTTP/1.1\r\n" |
| 20778 | "Host: www.example.org\r\n" |
| 20779 | "Connection: keep-alive\r\n"), |
| 20780 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 20781 | }; |
| 20782 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 20783 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20785 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20786 | // Insecure url |
| 20787 | url_ = "http://www.example.org/"; |
| 20788 | request_.url = GURL(url_); |
| 20789 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20790 | TestCompletionCallback callback; |
| 20791 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20792 | auto trans = |
| 20793 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20794 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20795 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20796 | |
| 20797 | std::string response_data; |
| 20798 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20799 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20800 | |
| 20801 | // Insecure request does not generate a report |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20802 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20803 | } |
| 20804 | |
| 20805 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20806 | DontCreateReportHttpError) { |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20807 | RequestPolicy(); |
| 20808 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 20809 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20810 | |
| 20811 | // Make HTTP request that fails |
| 20812 | MockRead data_reads[] = { |
| 20813 | MockRead("hello world"), |
| 20814 | MockRead(SYNCHRONOUS, OK), |
| 20815 | }; |
| 20816 | |
| 20817 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 20818 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20819 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20820 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 20821 | request_.url = GURL(url_); |
| 20822 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20824 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20825 | auto trans = |
| 20826 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20827 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20828 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20829 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 20830 | |
| 20831 | // Insecure request does not generate a report, regardless of existence of a |
| 20832 | // policy for the origin. |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 20833 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 20834 | } |
| 20835 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 20836 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 20837 | // proxy. |
| 20838 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 20839 | HttpRequestInfo request; |
| 20840 | request.method = "GET"; |
| 20841 | request.url = GURL("https://www.example.org/"); |
| 20842 | request.traffic_annotation = |
| 20843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20844 | |
| 20845 | // Configure against proxy server "myproxy:70". |
| 20846 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 20847 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 20848 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20849 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20850 | |
| 20851 | // Since we have proxy, should try to establish tunnel. |
| 20852 | MockWrite data_writes1[] = { |
| 20853 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20854 | "Host: www.example.org:443\r\n" |
| 20855 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 20856 | }; |
| 20857 | |
| 20858 | // The proxy responds to the connect with a 407, using a non-persistent |
| 20859 | // connection. |
| 20860 | MockRead data_reads1[] = { |
| 20861 | // No credentials. |
| 20862 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 20863 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 20864 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 20865 | }; |
| 20866 | |
| 20867 | MockWrite data_writes2[] = { |
| 20868 | // After calling trans->RestartWithAuth(), this is the request we should |
| 20869 | // be issuing -- the final header line contains the credentials. |
| 20870 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20871 | "Host: www.example.org:443\r\n" |
| 20872 | "Proxy-Connection: keep-alive\r\n" |
| 20873 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 20874 | |
| 20875 | MockWrite("GET / HTTP/1.1\r\n" |
| 20876 | "Host: www.example.org\r\n" |
| 20877 | "Connection: keep-alive\r\n\r\n"), |
| 20878 | }; |
| 20879 | |
| 20880 | MockRead data_reads2[] = { |
| 20881 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 20882 | |
| 20883 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20884 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 20885 | MockRead("Content-Length: 5\r\n\r\n"), |
| 20886 | MockRead(SYNCHRONOUS, "hello"), |
| 20887 | }; |
| 20888 | |
| 20889 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 20890 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20891 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 20892 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20893 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20895 | |
| 20896 | TestCompletionCallback callback1; |
| 20897 | |
| 20898 | auto trans = |
| 20899 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20900 | |
| 20901 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 20902 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 20903 | |
| 20904 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20905 | EXPECT_EQ(407, response->headers->response_code()); |
| 20906 | |
| 20907 | std::string response_data; |
| 20908 | rv = ReadTransaction(trans.get(), &response_data); |
| 20909 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 20910 | |
| 20911 | // No NEL report is generated for the 407. |
| 20912 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 20913 | |
| 20914 | TestCompletionCallback callback2; |
| 20915 | |
| 20916 | rv = |
| 20917 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 20918 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 20919 | |
| 20920 | response = trans->GetResponseInfo(); |
| 20921 | EXPECT_EQ(200, response->headers->response_code()); |
| 20922 | |
| 20923 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20924 | EXPECT_EQ("hello", response_data); |
| 20925 | |
| 20926 | trans.reset(); |
| 20927 | |
| 20928 | // No NEL report is generated because we are behind a proxy. |
| 20929 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 20930 | } |
| 20931 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20932 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 20933 | ReportContainsUploadDepth) { |
| 20934 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20935 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20936 | RequestPolicy(); |
| 20937 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20938 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20939 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20940 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 20941 | } |
| 20942 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20943 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 20944 | std::string extra_header_string = extra_headers_.ToString(); |
| 20945 | static const base::TimeDelta kSleepDuration = |
| 20946 | base::TimeDelta::FromMilliseconds(10); |
| 20947 | |
| 20948 | std::vector<MockWrite> data_writes = { |
| 20949 | MockWrite(ASYNC, 0, |
| 20950 | "GET / HTTP/1.1\r\n" |
| 20951 | "Host: www.example.org\r\n" |
| 20952 | "Connection: keep-alive\r\n"), |
| 20953 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 20954 | }; |
| 20955 | |
| 20956 | std::vector<MockRead> data_reads = { |
| 20957 | // Write one byte of the status line, followed by a pause. |
| 20958 | MockRead(ASYNC, 2, "H"), |
| 20959 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 20960 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 20961 | MockRead(ASYNC, 5, "hello world"), |
| 20962 | MockRead(SYNCHRONOUS, OK, 6), |
| 20963 | }; |
| 20964 | |
| 20965 | SequencedSocketData data(data_reads, data_writes); |
| 20966 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20967 | |
| 20968 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20970 | |
| 20971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20972 | |
| 20973 | auto trans = |
| 20974 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20975 | |
| 20976 | TestCompletionCallback callback; |
| 20977 | |
| 20978 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20980 | |
| 20981 | data.RunUntilPaused(); |
| 20982 | ASSERT_TRUE(data.IsPaused()); |
| 20983 | FastForwardBy(kSleepDuration); |
| 20984 | data.Resume(); |
| 20985 | |
| 20986 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20987 | |
| 20988 | std::string response_data; |
| 20989 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20990 | EXPECT_EQ("hello world", response_data); |
| 20991 | |
| 20992 | trans.reset(); |
| 20993 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20994 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20995 | |
| 20996 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20997 | |
| 20998 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20999 | network_error_logging_service()->errors()[0]; |
| 21000 | |
| 21001 | // Sanity-check elapsed time in error report |
| 21002 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 21003 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 21004 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 21005 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 21006 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 21007 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 21008 | HttpRequestInfo request; |
| 21009 | request.method = "GET"; |
| 21010 | request.url = GURL("http://example.org/"); |
| 21011 | |
| 21012 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 21013 | |
| 21014 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 21016 | TestCompletionCallback callback1; |
| 21017 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 21018 | |
| 21019 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 21020 | } |
| 21021 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21022 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21023 | static const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21024 | HttpRequestInfo request; |
| 21025 | request.method = "GET"; |
| 21026 | request.url = GURL("https://www.example.org/"); |
| 21027 | request.traffic_annotation = |
| 21028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21029 | |
| 21030 | MockWrite data_writes[] = { |
| 21031 | MockWrite("GET / HTTP/1.1\r\n" |
| 21032 | "Host: www.example.org\r\n" |
| 21033 | "Connection: keep-alive\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); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21045 | ssl.connect_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21046 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21047 | ssl.confirm_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21048 | session_deps_.enable_early_data = true; |
| 21049 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21050 | |
| 21051 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21052 | |
| 21053 | TestCompletionCallback callback; |
| 21054 | auto trans = |
| 21055 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21056 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21057 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21058 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21060 | |
| 21061 | rv = callback.WaitForResult(); |
| 21062 | EXPECT_THAT(rv, IsOk()); |
| 21063 | |
| 21064 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21065 | ASSERT_TRUE(response); |
| 21066 | ASSERT_TRUE(response->headers); |
| 21067 | EXPECT_EQ(200, response->headers->response_code()); |
| 21068 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21069 | |
| 21070 | // Check that ConfirmHandshake wasn't called. |
| 21071 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 21072 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 21073 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21074 | // The handshake time should include the time it took to run Connect(), but |
| 21075 | // not ConfirmHandshake(). |
| 21076 | LoadTimingInfo load_timing_info; |
| 21077 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 21078 | EXPECT_EQ(load_timing_info.connect_timing.connect_start, start_time); |
| 21079 | EXPECT_EQ(load_timing_info.connect_timing.ssl_start, start_time); |
| 21080 | EXPECT_EQ(load_timing_info.connect_timing.ssl_end, start_time + kDelay); |
| 21081 | EXPECT_EQ(load_timing_info.connect_timing.connect_end, start_time + kDelay); |
| 21082 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21083 | trans.reset(); |
| 21084 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21085 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21086 | } |
| 21087 | |
| 21088 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21089 | static const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21090 | HttpRequestInfo request; |
| 21091 | request.method = "POST"; |
| 21092 | request.url = GURL("https://www.example.org/"); |
| 21093 | request.traffic_annotation = |
| 21094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21095 | |
| 21096 | MockWrite data_writes[] = { |
| 21097 | MockWrite(SYNCHRONOUS, |
| 21098 | "POST / HTTP/1.1\r\n" |
| 21099 | "Host: www.example.org\r\n" |
| 21100 | "Connection: keep-alive\r\n" |
| 21101 | "Content-Length: 0\r\n\r\n"), |
| 21102 | }; |
| 21103 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21104 | MockRead data_reads[] = { |
| 21105 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21106 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21107 | MockRead(SYNCHRONOUS, "1"), |
| 21108 | }; |
| 21109 | |
| 21110 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21112 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21113 | ssl.connect_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21114 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21115 | ssl.confirm_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21116 | session_deps_.enable_early_data = true; |
| 21117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21118 | |
| 21119 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21120 | |
| 21121 | TestCompletionCallback callback; |
| 21122 | auto trans = |
| 21123 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21124 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21125 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21126 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21128 | |
| 21129 | rv = callback.WaitForResult(); |
| 21130 | EXPECT_THAT(rv, IsOk()); |
| 21131 | |
| 21132 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21133 | ASSERT_TRUE(response); |
| 21134 | ASSERT_TRUE(response->headers); |
| 21135 | EXPECT_EQ(200, response->headers->response_code()); |
| 21136 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21137 | |
| 21138 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21139 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21140 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21141 | // The handshake time should include the time it took to run Connect(), but |
| 21142 | // not ConfirmHandshake(). If ConfirmHandshake() returns synchronously, we |
| 21143 | // assume the connection did not negotiate 0-RTT or the handshake was already |
| 21144 | // confirmed. |
| 21145 | LoadTimingInfo load_timing_info; |
| 21146 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 21147 | EXPECT_EQ(load_timing_info.connect_timing.connect_start, start_time); |
| 21148 | EXPECT_EQ(load_timing_info.connect_timing.ssl_start, start_time); |
| 21149 | EXPECT_EQ(load_timing_info.connect_timing.ssl_end, start_time + kDelay); |
| 21150 | EXPECT_EQ(load_timing_info.connect_timing.connect_end, start_time + kDelay); |
| 21151 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21152 | trans.reset(); |
| 21153 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21154 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21155 | } |
| 21156 | |
| 21157 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 21158 | HttpRequestInfo request; |
| 21159 | request.method = "POST"; |
| 21160 | request.url = GURL("https://www.example.org/"); |
| 21161 | request.traffic_annotation = |
| 21162 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21163 | |
| 21164 | MockWrite data_writes[] = { |
| 21165 | MockWrite(ASYNC, |
| 21166 | "POST / HTTP/1.1\r\n" |
| 21167 | "Host: www.example.org\r\n" |
| 21168 | "Connection: keep-alive\r\n" |
| 21169 | "Content-Length: 0\r\n\r\n"), |
| 21170 | }; |
| 21171 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21172 | MockRead data_reads[] = { |
| 21173 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21174 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21175 | MockRead(SYNCHRONOUS, "1"), |
| 21176 | }; |
| 21177 | |
| 21178 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21179 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21180 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21181 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 21182 | session_deps_.enable_early_data = true; |
| 21183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21184 | |
| 21185 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21186 | |
| 21187 | TestCompletionCallback callback; |
| 21188 | auto trans = |
| 21189 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21190 | |
| 21191 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21192 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21193 | |
| 21194 | rv = callback.WaitForResult(); |
| 21195 | EXPECT_THAT(rv, IsOk()); |
| 21196 | |
| 21197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21198 | ASSERT_TRUE(response); |
| 21199 | ASSERT_TRUE(response->headers); |
| 21200 | EXPECT_EQ(200, response->headers->response_code()); |
| 21201 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21202 | |
| 21203 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21204 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21205 | |
| 21206 | trans.reset(); |
| 21207 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21208 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21209 | } |
| 21210 | |
| 21211 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21212 | static const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(10); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21213 | HttpRequestInfo request; |
| 21214 | request.method = "POST"; |
| 21215 | request.url = GURL("https://www.example.org/"); |
| 21216 | request.traffic_annotation = |
| 21217 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21218 | |
| 21219 | MockWrite data_writes[] = { |
| 21220 | MockWrite(SYNCHRONOUS, |
| 21221 | "POST / HTTP/1.1\r\n" |
| 21222 | "Host: www.example.org\r\n" |
| 21223 | "Connection: keep-alive\r\n" |
| 21224 | "Content-Length: 0\r\n\r\n"), |
| 21225 | }; |
| 21226 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21227 | MockRead data_reads[] = { |
| 21228 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21229 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21230 | MockRead(SYNCHRONOUS, "1"), |
| 21231 | }; |
| 21232 | |
| 21233 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21234 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21235 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21236 | ssl.connect_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21237 | ssl.confirm = MockConfirm(ASYNC, OK); |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21238 | ssl.confirm_callback = FastForwardByCallback(kDelay); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21239 | session_deps_.enable_early_data = true; |
| 21240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21241 | |
| 21242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21243 | |
| 21244 | TestCompletionCallback callback; |
| 21245 | auto trans = |
| 21246 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21247 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21248 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21249 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21251 | |
| 21252 | rv = callback.WaitForResult(); |
| 21253 | EXPECT_THAT(rv, IsOk()); |
| 21254 | |
| 21255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21256 | ASSERT_TRUE(response); |
| 21257 | ASSERT_TRUE(response->headers); |
| 21258 | EXPECT_EQ(200, response->headers->response_code()); |
| 21259 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21260 | |
| 21261 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21262 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21263 | |
David Benjamin | bae08ba | 2019-10-18 21:06:15 | [diff] [blame] | 21264 | // The handshake time should include the time it took to run Connect() and |
| 21265 | // ConfirmHandshake(). |
| 21266 | LoadTimingInfo load_timing_info; |
| 21267 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 21268 | EXPECT_EQ(load_timing_info.connect_timing.connect_start, start_time); |
| 21269 | EXPECT_EQ(load_timing_info.connect_timing.ssl_start, start_time); |
| 21270 | EXPECT_EQ(load_timing_info.connect_timing.ssl_end, start_time + 2 * kDelay); |
| 21271 | EXPECT_EQ(load_timing_info.connect_timing.connect_end, |
| 21272 | start_time + 2 * kDelay); |
| 21273 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21274 | trans.reset(); |
| 21275 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21276 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21277 | } |
| 21278 | |
| 21279 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 21280 | HttpRequestInfo request; |
| 21281 | request.method = "POST"; |
| 21282 | request.url = GURL("https://www.example.org/"); |
| 21283 | request.traffic_annotation = |
| 21284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21285 | |
| 21286 | MockWrite data_writes[] = { |
| 21287 | MockWrite(ASYNC, |
| 21288 | "POST / HTTP/1.1\r\n" |
| 21289 | "Host: www.example.org\r\n" |
| 21290 | "Connection: keep-alive\r\n" |
| 21291 | "Content-Length: 0\r\n\r\n"), |
| 21292 | }; |
| 21293 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21294 | MockRead data_reads[] = { |
| 21295 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21296 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21297 | MockRead(SYNCHRONOUS, "1"), |
| 21298 | }; |
| 21299 | |
| 21300 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21301 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21302 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21303 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 21304 | session_deps_.enable_early_data = true; |
| 21305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21306 | |
| 21307 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21308 | |
| 21309 | TestCompletionCallback callback; |
| 21310 | auto trans = |
| 21311 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21312 | |
| 21313 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21314 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21315 | |
| 21316 | rv = callback.WaitForResult(); |
| 21317 | EXPECT_THAT(rv, IsOk()); |
| 21318 | |
| 21319 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21320 | ASSERT_TRUE(response); |
| 21321 | ASSERT_TRUE(response->headers); |
| 21322 | EXPECT_EQ(200, response->headers->response_code()); |
| 21323 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21324 | |
| 21325 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21326 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21327 | |
| 21328 | trans.reset(); |
| 21329 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21330 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21331 | } |
| 21332 | |
David Benjamin | fb97693 | 2019-05-15 13:39:15 | [diff] [blame] | 21333 | // 0-RTT rejects are handled at HttpNetworkTransaction. |
| 21334 | TEST_F(HttpNetworkTransactionTest, ZeroRTTReject) { |
| 21335 | enum class RejectType { |
| 21336 | kRead, |
| 21337 | kWrite, |
| 21338 | kConfirm, |
| 21339 | }; |
| 21340 | |
| 21341 | for (RejectType type : |
| 21342 | {RejectType::kRead, RejectType::kWrite, RejectType::kConfirm}) { |
| 21343 | SCOPED_TRACE(static_cast<int>(type)); |
| 21344 | for (Error reject_error : |
| 21345 | {ERR_EARLY_DATA_REJECTED, ERR_WRONG_VERSION_ON_EARLY_DATA}) { |
| 21346 | SCOPED_TRACE(reject_error); |
| 21347 | session_deps_.socket_factory = |
| 21348 | std::make_unique<MockClientSocketFactory>(); |
| 21349 | |
| 21350 | HttpRequestInfo request; |
| 21351 | request.method = type == RejectType::kConfirm ? "POST" : "GET"; |
| 21352 | request.url = GURL("https://www.example.org/"); |
| 21353 | request.traffic_annotation = |
| 21354 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21355 | |
| 21356 | // The first request fails. |
| 21357 | std::vector<MockWrite> data1_writes; |
| 21358 | std::vector<MockRead> data1_reads; |
| 21359 | SSLSocketDataProvider ssl1(SYNCHRONOUS, OK); |
| 21360 | switch (type) { |
| 21361 | case RejectType::kRead: |
| 21362 | data1_writes.emplace_back( |
| 21363 | "GET / HTTP/1.1\r\n" |
| 21364 | "Host: www.example.org\r\n" |
| 21365 | "Connection: keep-alive\r\n\r\n"); |
| 21366 | data1_reads.emplace_back(ASYNC, reject_error); |
| 21367 | // Cause ConfirmHandshake to hang (it should not be called). |
| 21368 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 21369 | break; |
| 21370 | case RejectType::kWrite: |
| 21371 | data1_writes.emplace_back(ASYNC, reject_error); |
| 21372 | // Cause ConfirmHandshake to hang (it should not be called). |
| 21373 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 21374 | break; |
| 21375 | case RejectType::kConfirm: |
| 21376 | // The request never gets far enough to read or write. |
| 21377 | ssl1.confirm = MockConfirm(ASYNC, reject_error); |
| 21378 | break; |
| 21379 | } |
| 21380 | |
| 21381 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 21382 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21383 | session_deps_.enable_early_data = true; |
| 21384 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 21385 | |
| 21386 | // The retry succeeds. |
| 21387 | // |
| 21388 | // TODO(https://crbug.com/950705): If |reject_error| is |
| 21389 | // ERR_EARLY_DATA_REJECTED, the retry should happen over the same socket. |
| 21390 | MockWrite data2_writes[] = { |
| 21391 | request.method == "POST" |
| 21392 | ? MockWrite("POST / HTTP/1.1\r\n" |
| 21393 | "Host: www.example.org\r\n" |
| 21394 | "Connection: keep-alive\r\n" |
| 21395 | "Content-Length: 0\r\n\r\n") |
| 21396 | : MockWrite("GET / HTTP/1.1\r\n" |
| 21397 | "Host: www.example.org\r\n" |
| 21398 | "Connection: keep-alive\r\n\r\n"), |
| 21399 | }; |
| 21400 | |
| 21401 | MockRead data2_reads[] = { |
| 21402 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21403 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21404 | MockRead(SYNCHRONOUS, "1"), |
| 21405 | }; |
| 21406 | |
| 21407 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 21408 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21409 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 21410 | ssl2.confirm = MockConfirm(ASYNC, OK); |
| 21411 | session_deps_.enable_early_data = true; |
| 21412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 21413 | |
| 21414 | std::unique_ptr<HttpNetworkSession> session( |
| 21415 | CreateSession(&session_deps_)); |
| 21416 | |
| 21417 | TestCompletionCallback callback; |
| 21418 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21419 | session.get()); |
| 21420 | |
| 21421 | EXPECT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 21422 | NetLogWithSource())), |
| 21423 | IsOk()); |
| 21424 | |
| 21425 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 21426 | ASSERT_TRUE(response); |
| 21427 | ASSERT_TRUE(response->headers); |
| 21428 | EXPECT_EQ(200, response->headers->response_code()); |
| 21429 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 21430 | } |
| 21431 | } |
| 21432 | } |
| 21433 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21434 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 21435 | HttpRequestInfo request; |
| 21436 | request.method = "POST"; |
| 21437 | request.url = GURL("https://www.example.org/"); |
| 21438 | request.traffic_annotation = |
| 21439 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21440 | |
| 21441 | MockWrite data_writes[] = { |
| 21442 | MockWrite("POST / HTTP/1.1\r\n" |
| 21443 | "Host: www.example.org\r\n" |
| 21444 | "Connection: keep-alive\r\n" |
| 21445 | "Content-Length: 0\r\n\r\n"), |
| 21446 | }; |
| 21447 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21448 | MockRead data_reads[] = { |
| 21449 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21450 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21451 | MockRead(SYNCHRONOUS, "1"), |
| 21452 | }; |
| 21453 | |
| 21454 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21455 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21456 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21457 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 21458 | session_deps_.enable_early_data = true; |
| 21459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21460 | |
| 21461 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21462 | |
| 21463 | TestCompletionCallback callback; |
| 21464 | auto trans = |
| 21465 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21466 | |
| 21467 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21469 | |
| 21470 | rv = callback.WaitForResult(); |
| 21471 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 21472 | |
| 21473 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21474 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21475 | |
| 21476 | trans.reset(); |
| 21477 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21478 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21479 | } |
| 21480 | |
| 21481 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 21482 | HttpRequestInfo request; |
| 21483 | request.method = "POST"; |
| 21484 | request.url = GURL("https://www.example.org/"); |
| 21485 | request.traffic_annotation = |
| 21486 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21487 | |
| 21488 | MockWrite data_writes[] = { |
| 21489 | MockWrite("POST / HTTP/1.1\r\n" |
| 21490 | "Host: www.example.org\r\n" |
| 21491 | "Connection: keep-alive\r\n" |
| 21492 | "Content-Length: 0\r\n\r\n"), |
| 21493 | }; |
| 21494 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21495 | MockRead data_reads[] = { |
| 21496 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 21497 | MockRead("Content-Length: 1\r\n\r\n"), |
| 21498 | MockRead(SYNCHRONOUS, "1"), |
| 21499 | }; |
| 21500 | |
| 21501 | StaticSocketDataProvider data(data_reads, data_writes); |
| 21502 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21503 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 21504 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 21505 | session_deps_.enable_early_data = true; |
| 21506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 21507 | |
| 21508 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21509 | |
| 21510 | TestCompletionCallback callback; |
| 21511 | auto trans = |
| 21512 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21513 | |
| 21514 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21515 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21516 | |
| 21517 | rv = callback.WaitForResult(); |
| 21518 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 21519 | |
| 21520 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 21521 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 21522 | |
| 21523 | trans.reset(); |
| 21524 | |
Matt Menke | 433de6d | 2020-03-04 00:24:11 | [diff] [blame] | 21525 | session->CloseAllConnections(ERR_FAILED, "Very good reason"); |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 21526 | } |
| 21527 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21528 | // Test the proxy and origin server each requesting both TLS client certificates |
| 21529 | // and HTTP auth. This is a regression test for https://crbug.com/946406. |
| 21530 | TEST_F(HttpNetworkTransactionTest, AuthEverything) { |
| 21531 | // Note these hosts must match the CheckBasic*Auth() functions. |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 21532 | session_deps_.proxy_resolution_service = |
| 21533 | ConfiguredProxyResolutionService::CreateFixed( |
| 21534 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21535 | |
| 21536 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21537 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 21538 | |
| 21539 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 21540 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21541 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21542 | ASSERT_TRUE(identity_proxy); |
| 21543 | |
| 21544 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21545 | cert_request_info_origin->host_and_port = |
| 21546 | HostPortPair("www.example.org", 443); |
| 21547 | |
| 21548 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 21549 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21550 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 21551 | ASSERT_TRUE(identity_origin); |
| 21552 | |
| 21553 | HttpRequestInfo request; |
| 21554 | request.method = "GET"; |
| 21555 | request.url = GURL("https://www.example.org/"); |
| 21556 | request.traffic_annotation = |
| 21557 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21558 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21559 | // First, the client connects to the proxy, which requests a client |
| 21560 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21561 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21562 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 21563 | ssl_proxy1.expected_send_client_cert = false; |
| 21564 | StaticSocketDataProvider data1; |
| 21565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21567 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21568 | // The client responds with a certificate on a new connection. The handshake |
| 21569 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21570 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21571 | ssl_proxy2.expected_send_client_cert = true; |
| 21572 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21573 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21574 | std::vector<MockWrite> mock_writes2; |
| 21575 | std::vector<MockRead> mock_reads2; |
| 21576 | mock_writes2.emplace_back( |
| 21577 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21578 | "Host: www.example.org:443\r\n" |
| 21579 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 21580 | mock_reads2.emplace_back( |
| 21581 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21582 | "Content-Length: 0\r\n" |
| 21583 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21584 | // The client retries with credentials. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21585 | mock_writes2.emplace_back( |
| 21586 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21587 | "Host: www.example.org:443\r\n" |
| 21588 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21589 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21590 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21591 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21592 | // The origin requests client certificates. |
| 21593 | SSLSocketDataProvider ssl_origin2(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21594 | ssl_origin2.cert_request_info = cert_request_info_origin.get(); |
| 21595 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 21596 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 21598 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21599 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21600 | // The client responds to the origin client certificate request on a new |
| 21601 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21602 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 21603 | ssl_proxy3.expected_send_client_cert = true; |
| 21604 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 21605 | std::vector<MockWrite> mock_writes3; |
| 21606 | std::vector<MockRead> mock_reads3; |
| 21607 | mock_writes3.emplace_back( |
| 21608 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21609 | "Host: www.example.org:443\r\n" |
| 21610 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21611 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21612 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21613 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21614 | SSLSocketDataProvider ssl_origin3(ASYNC, OK); |
| 21615 | ssl_origin3.expected_send_client_cert = true; |
| 21616 | ssl_origin3.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21617 | // The client sends the origin HTTP request, which results in another HTTP |
| 21618 | // auth request. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21619 | mock_writes3.emplace_back( |
| 21620 | "GET / HTTP/1.1\r\n" |
| 21621 | "Host: www.example.org\r\n" |
| 21622 | "Connection: keep-alive\r\n\r\n"); |
| 21623 | mock_reads3.emplace_back( |
| 21624 | "HTTP/1.1 401 Unauthorized\r\n" |
| 21625 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 21626 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21627 | // The client retries with credentials, and the request finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21628 | mock_writes3.emplace_back( |
| 21629 | "GET / HTTP/1.1\r\n" |
| 21630 | "Host: www.example.org\r\n" |
| 21631 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21632 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21633 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21634 | mock_reads3.emplace_back( |
| 21635 | "HTTP/1.1 200 OK\r\n" |
| 21636 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21637 | // The client makes another request. This should reuse the socket with all |
| 21638 | // credentials cached. |
| 21639 | mock_writes3.emplace_back( |
| 21640 | "GET / HTTP/1.1\r\n" |
| 21641 | "Host: www.example.org\r\n" |
| 21642 | "Connection: keep-alive\r\n" |
| 21643 | // Authenticate as user:pass. |
| 21644 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21645 | mock_reads3.emplace_back( |
| 21646 | "HTTP/1.1 200 OK\r\n" |
| 21647 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21648 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 21649 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21650 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 21651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21652 | |
| 21653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21654 | |
| 21655 | // Start the request. |
| 21656 | TestCompletionCallback callback; |
| 21657 | auto trans = |
| 21658 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21659 | int rv = callback.GetResult( |
| 21660 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 21661 | |
| 21662 | // Handle the proxy client certificate challenge. |
| 21663 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21664 | SSLCertRequestInfo* cert_request_info = |
| 21665 | trans->GetResponseInfo()->cert_request_info.get(); |
| 21666 | ASSERT_TRUE(cert_request_info); |
| 21667 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 21668 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21669 | cert_request_info_proxy->host_and_port); |
| 21670 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21671 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 21672 | callback.callback())); |
| 21673 | |
| 21674 | // Handle the proxy HTTP auth challenge. |
| 21675 | ASSERT_THAT(rv, IsOk()); |
| 21676 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 21677 | EXPECT_TRUE( |
| 21678 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21679 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21680 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 21681 | callback.callback())); |
| 21682 | |
| 21683 | // Handle the origin client certificate challenge. |
| 21684 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21685 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 21686 | ASSERT_TRUE(cert_request_info); |
| 21687 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 21688 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21689 | cert_request_info_origin->host_and_port); |
| 21690 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21691 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 21692 | callback.callback())); |
| 21693 | |
| 21694 | // Handle the origin HTTP auth challenge. |
| 21695 | ASSERT_THAT(rv, IsOk()); |
| 21696 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 21697 | EXPECT_TRUE( |
| 21698 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21699 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21700 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 21701 | callback.callback())); |
| 21702 | |
| 21703 | // The request completes. |
| 21704 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21705 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21706 | |
| 21707 | // Make a second request. This time all credentials are cached. |
| 21708 | trans = |
| 21709 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21710 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 21711 | NetLogWithSource())), |
| 21712 | IsOk()); |
| 21713 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21714 | } |
| 21715 | |
| 21716 | // Test the proxy and origin server each requesting both TLS client certificates |
| 21717 | // and HTTP auth and each HTTP auth closing the connection. This is a regression |
| 21718 | // test for https://crbug.com/946406. |
| 21719 | TEST_F(HttpNetworkTransactionTest, AuthEverythingWithConnectClose) { |
| 21720 | // Note these hosts must match the CheckBasic*Auth() functions. |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 21721 | session_deps_.proxy_resolution_service = |
| 21722 | ConfiguredProxyResolutionService::CreateFixed( |
| 21723 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21724 | |
| 21725 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21726 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 21727 | |
| 21728 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 21729 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21730 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21731 | ASSERT_TRUE(identity_proxy); |
| 21732 | |
| 21733 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21734 | cert_request_info_origin->host_and_port = |
| 21735 | HostPortPair("www.example.org", 443); |
| 21736 | |
| 21737 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 21738 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21739 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 21740 | ASSERT_TRUE(identity_origin); |
| 21741 | |
| 21742 | HttpRequestInfo request; |
| 21743 | request.method = "GET"; |
| 21744 | request.url = GURL("https://www.example.org/"); |
| 21745 | request.traffic_annotation = |
| 21746 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21747 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21748 | // First, the client connects to the proxy, which requests a client |
| 21749 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21750 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21751 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 21752 | ssl_proxy1.expected_send_client_cert = false; |
| 21753 | StaticSocketDataProvider data1; |
| 21754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21756 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21757 | // The client responds with a certificate on a new connection. The handshake |
| 21758 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21759 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21760 | ssl_proxy2.expected_send_client_cert = true; |
| 21761 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21762 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21763 | std::vector<MockWrite> mock_writes2; |
| 21764 | std::vector<MockRead> mock_reads2; |
| 21765 | mock_writes2.emplace_back( |
| 21766 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21767 | "Host: www.example.org:443\r\n" |
| 21768 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 21769 | mock_reads2.emplace_back( |
| 21770 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21771 | "Content-Length: 0\r\n" |
| 21772 | "Proxy-Connection: close\r\n" |
| 21773 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 21774 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 21775 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21777 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21778 | // The client retries with credentials on a new connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21779 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 21780 | ssl_proxy3.expected_send_client_cert = true; |
| 21781 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 21782 | std::vector<MockWrite> mock_writes3; |
| 21783 | std::vector<MockRead> mock_reads3; |
| 21784 | mock_writes3.emplace_back( |
| 21785 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21786 | "Host: www.example.org:443\r\n" |
| 21787 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21788 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21789 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21790 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21791 | // The origin requests client certificates. |
| 21792 | SSLSocketDataProvider ssl_origin3(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21793 | ssl_origin3.cert_request_info = cert_request_info_origin.get(); |
| 21794 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 21795 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21796 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 21797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21798 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21799 | // The client responds to the origin client certificate request on a new |
| 21800 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21801 | SSLSocketDataProvider ssl_proxy4(ASYNC, OK); |
| 21802 | ssl_proxy4.expected_send_client_cert = true; |
| 21803 | ssl_proxy4.expected_client_cert = identity_proxy->certificate(); |
| 21804 | std::vector<MockWrite> mock_writes4; |
| 21805 | std::vector<MockRead> mock_reads4; |
| 21806 | mock_writes4.emplace_back( |
| 21807 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21808 | "Host: www.example.org:443\r\n" |
| 21809 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21810 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21811 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21812 | mock_reads4.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21813 | SSLSocketDataProvider ssl_origin4(ASYNC, OK); |
| 21814 | ssl_origin4.expected_send_client_cert = true; |
| 21815 | ssl_origin4.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21816 | // The client sends the origin HTTP request, which results in another HTTP |
| 21817 | // auth request and closed connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21818 | mock_writes4.emplace_back( |
| 21819 | "GET / HTTP/1.1\r\n" |
| 21820 | "Host: www.example.org\r\n" |
| 21821 | "Connection: keep-alive\r\n\r\n"); |
| 21822 | mock_reads4.emplace_back( |
| 21823 | "HTTP/1.1 401 Unauthorized\r\n" |
| 21824 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 21825 | "Connection: close\r\n" |
| 21826 | "Content-Length: 0\r\n\r\n"); |
| 21827 | StaticSocketDataProvider data4(mock_reads4, mock_writes4); |
| 21828 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21829 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy4); |
| 21830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin4); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21831 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21832 | // The client retries with credentials on a new connection, and the request |
| 21833 | // finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21834 | SSLSocketDataProvider ssl_proxy5(ASYNC, OK); |
| 21835 | ssl_proxy5.expected_send_client_cert = true; |
| 21836 | ssl_proxy5.expected_client_cert = identity_proxy->certificate(); |
| 21837 | std::vector<MockWrite> mock_writes5; |
| 21838 | std::vector<MockRead> mock_reads5; |
| 21839 | mock_writes5.emplace_back( |
| 21840 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21841 | "Host: www.example.org:443\r\n" |
| 21842 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21843 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21844 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21845 | mock_reads5.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21846 | SSLSocketDataProvider ssl_origin5(ASYNC, OK); |
| 21847 | ssl_origin5.expected_send_client_cert = true; |
| 21848 | ssl_origin5.expected_client_cert = identity_origin->certificate(); |
| 21849 | mock_writes5.emplace_back( |
| 21850 | "GET / HTTP/1.1\r\n" |
| 21851 | "Host: www.example.org\r\n" |
| 21852 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21853 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21854 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21855 | mock_reads5.emplace_back( |
| 21856 | "HTTP/1.1 200 OK\r\n" |
| 21857 | "Connection: close\r\n" |
| 21858 | "Content-Length: 0\r\n\r\n"); |
| 21859 | StaticSocketDataProvider data5(mock_reads5, mock_writes5); |
| 21860 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21861 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy5); |
| 21862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin5); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21863 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21864 | // The client makes a second request. This needs yet another connection, but |
| 21865 | // all credentials are cached. |
| 21866 | SSLSocketDataProvider ssl_proxy6(ASYNC, OK); |
| 21867 | ssl_proxy6.expected_send_client_cert = true; |
| 21868 | ssl_proxy6.expected_client_cert = identity_proxy->certificate(); |
| 21869 | std::vector<MockWrite> mock_writes6; |
| 21870 | std::vector<MockRead> mock_reads6; |
| 21871 | mock_writes6.emplace_back( |
| 21872 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21873 | "Host: www.example.org:443\r\n" |
| 21874 | "Proxy-Connection: keep-alive\r\n" |
| 21875 | // Authenticate as proxyuser:proxypass. |
| 21876 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21877 | mock_reads6.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21878 | SSLSocketDataProvider ssl_origin6(ASYNC, OK); |
| 21879 | ssl_origin6.expected_send_client_cert = true; |
| 21880 | ssl_origin6.expected_client_cert = identity_origin->certificate(); |
| 21881 | mock_writes6.emplace_back( |
| 21882 | "GET / HTTP/1.1\r\n" |
| 21883 | "Host: www.example.org\r\n" |
| 21884 | "Connection: keep-alive\r\n" |
| 21885 | // Authenticate as user:pass. |
| 21886 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 21887 | mock_reads6.emplace_back( |
| 21888 | "HTTP/1.1 200 OK\r\n" |
| 21889 | "Connection: close\r\n" |
| 21890 | "Content-Length: 0\r\n\r\n"); |
| 21891 | StaticSocketDataProvider data6(mock_reads6, mock_writes6); |
| 21892 | session_deps_.socket_factory->AddSocketDataProvider(&data6); |
| 21893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy6); |
| 21894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin6); |
| 21895 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21896 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21897 | |
| 21898 | // Start the request. |
| 21899 | TestCompletionCallback callback; |
| 21900 | auto trans = |
| 21901 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21902 | int rv = callback.GetResult( |
| 21903 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 21904 | |
| 21905 | // Handle the proxy client certificate challenge. |
| 21906 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21907 | SSLCertRequestInfo* cert_request_info = |
| 21908 | trans->GetResponseInfo()->cert_request_info.get(); |
| 21909 | ASSERT_TRUE(cert_request_info); |
| 21910 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 21911 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21912 | cert_request_info_proxy->host_and_port); |
| 21913 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21914 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 21915 | callback.callback())); |
| 21916 | |
| 21917 | // Handle the proxy HTTP auth challenge. |
| 21918 | ASSERT_THAT(rv, IsOk()); |
| 21919 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 21920 | EXPECT_TRUE( |
| 21921 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21922 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21923 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 21924 | callback.callback())); |
| 21925 | |
| 21926 | // Handle the origin client certificate challenge. |
| 21927 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21928 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 21929 | ASSERT_TRUE(cert_request_info); |
| 21930 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 21931 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21932 | cert_request_info_origin->host_and_port); |
| 21933 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21934 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 21935 | callback.callback())); |
| 21936 | |
| 21937 | // Handle the origin HTTP auth challenge. |
| 21938 | ASSERT_THAT(rv, IsOk()); |
| 21939 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 21940 | EXPECT_TRUE( |
| 21941 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21942 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21943 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 21944 | callback.callback())); |
| 21945 | |
| 21946 | // The request completes. |
| 21947 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21948 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21949 | |
| 21950 | // Make a second request. This time all credentials are cached. |
| 21951 | trans = |
| 21952 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21953 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 21954 | NetLogWithSource())), |
| 21955 | IsOk()); |
| 21956 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21957 | } |
| 21958 | |
| 21959 | // Test the proxy requesting HTTP auth and the server requesting TLS client |
| 21960 | // certificates. This is a regression test for https://crbug.com/946406. |
| 21961 | TEST_F(HttpNetworkTransactionTest, ProxyHTTPAndServerTLSAuth) { |
| 21962 | // Note these hosts must match the CheckBasic*Auth() functions. |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 21963 | session_deps_.proxy_resolution_service = |
| 21964 | ConfiguredProxyResolutionService::CreateFixed( |
| 21965 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 21966 | |
| 21967 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21968 | cert_request_info_origin->host_and_port = |
| 21969 | HostPortPair("www.example.org", 443); |
| 21970 | |
| 21971 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 21972 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21973 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 21974 | ASSERT_TRUE(identity_origin); |
| 21975 | |
| 21976 | HttpRequestInfo request; |
| 21977 | request.method = "GET"; |
| 21978 | request.url = GURL("https://www.example.org/"); |
| 21979 | request.traffic_annotation = |
| 21980 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21981 | |
| 21982 | // The client connects to the proxy. The handshake succeeds. |
| 21983 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 21984 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 21985 | std::vector<MockWrite> mock_writes1; |
| 21986 | std::vector<MockRead> mock_reads1; |
| 21987 | mock_writes1.emplace_back( |
| 21988 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21989 | "Host: www.example.org:443\r\n" |
| 21990 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 21991 | mock_reads1.emplace_back( |
| 21992 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21993 | "Content-Length: 0\r\n" |
| 21994 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 21995 | // The client retries with credentials, and the request finally succeeds. |
| 21996 | mock_writes1.emplace_back( |
| 21997 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21998 | "Host: www.example.org:443\r\n" |
| 21999 | "Proxy-Connection: keep-alive\r\n" |
| 22000 | // Authenticate as proxyuser:proxypass. |
| 22001 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 22002 | mock_reads1.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 22003 | // The origin requests client certificates. |
| 22004 | SSLSocketDataProvider ssl_origin1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 22005 | ssl_origin1.cert_request_info = cert_request_info_origin.get(); |
| 22006 | StaticSocketDataProvider data1(mock_reads1, mock_writes1); |
| 22007 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 22009 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 22010 | |
| 22011 | // The client responds to the origin client certificate request on a new |
| 22012 | // connection. |
| 22013 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 22014 | std::vector<MockWrite> mock_writes2; |
| 22015 | std::vector<MockRead> mock_reads2; |
| 22016 | mock_writes2.emplace_back( |
| 22017 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 22018 | "Host: www.example.org:443\r\n" |
| 22019 | "Proxy-Connection: keep-alive\r\n" |
| 22020 | // Authenticate as proxyuser:proxypass. |
| 22021 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 22022 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 22023 | SSLSocketDataProvider ssl_origin2(ASYNC, OK); |
| 22024 | ssl_origin2.expected_send_client_cert = true; |
| 22025 | ssl_origin2.expected_client_cert = identity_origin->certificate(); |
| 22026 | // The client sends the origin HTTP request, which succeeds. |
| 22027 | mock_writes2.emplace_back( |
| 22028 | "GET / HTTP/1.1\r\n" |
| 22029 | "Host: www.example.org\r\n" |
| 22030 | "Connection: keep-alive\r\n\r\n"); |
| 22031 | mock_reads2.emplace_back( |
| 22032 | "HTTP/1.1 200 OK\r\n" |
| 22033 | "Content-Length: 0\r\n\r\n"); |
| 22034 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 22035 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22036 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 22037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 22038 | |
| 22039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22040 | |
| 22041 | // Start the request. |
| 22042 | TestCompletionCallback callback; |
| 22043 | auto trans = |
| 22044 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22045 | int rv = callback.GetResult( |
| 22046 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 22047 | |
| 22048 | // Handle the proxy HTTP auth challenge. |
| 22049 | ASSERT_THAT(rv, IsOk()); |
| 22050 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 22051 | EXPECT_TRUE( |
| 22052 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 22053 | rv = callback.GetResult(trans->RestartWithAuth( |
| 22054 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 22055 | callback.callback())); |
| 22056 | |
| 22057 | // Handle the origin client certificate challenge. |
| 22058 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 22059 | SSLCertRequestInfo* cert_request_info = |
| 22060 | trans->GetResponseInfo()->cert_request_info.get(); |
| 22061 | ASSERT_TRUE(cert_request_info); |
| 22062 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 22063 | EXPECT_EQ(cert_request_info->host_and_port, |
| 22064 | cert_request_info_origin->host_and_port); |
| 22065 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 22066 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 22067 | callback.callback())); |
| 22068 | |
| 22069 | // The request completes. |
| 22070 | ASSERT_THAT(rv, IsOk()); |
| 22071 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 22072 | } |
| 22073 | |
David Benjamin | 6e673a8 | 2019-04-30 22:52:58 | [diff] [blame] | 22074 | // Test that socket reuse works with client certificates. |
| 22075 | TEST_F(HttpNetworkTransactionTest, ClientCertSocketReuse) { |
| 22076 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 22077 | cert_request_info->host_and_port = HostPortPair("www.example.org", 443); |
| 22078 | |
| 22079 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 22080 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 22081 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 22082 | ASSERT_TRUE(identity); |
| 22083 | |
| 22084 | HttpRequestInfo request1; |
| 22085 | request1.method = "GET"; |
| 22086 | request1.url = GURL("https://www.example.org/a"); |
| 22087 | request1.traffic_annotation = |
| 22088 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22089 | |
| 22090 | HttpRequestInfo request2; |
| 22091 | request2.method = "GET"; |
| 22092 | request2.url = GURL("https://www.example.org/b"); |
| 22093 | request2.traffic_annotation = |
| 22094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22095 | |
| 22096 | // The first connection results in a client certificate request. |
| 22097 | StaticSocketDataProvider data1; |
| 22098 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22099 | SSLSocketDataProvider ssl1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 22100 | ssl1.cert_request_info = cert_request_info.get(); |
| 22101 | ssl1.expected_send_client_cert = false; |
| 22102 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 22103 | |
| 22104 | // The second connection succeeds and is usable for both requests. |
| 22105 | MockWrite mock_writes[] = { |
| 22106 | MockWrite("GET /a HTTP/1.1\r\n" |
| 22107 | "Host: www.example.org\r\n" |
| 22108 | "Connection: keep-alive\r\n\r\n"), |
| 22109 | MockWrite("GET /b HTTP/1.1\r\n" |
| 22110 | "Host: www.example.org\r\n" |
| 22111 | "Connection: keep-alive\r\n\r\n"), |
| 22112 | }; |
| 22113 | MockRead mock_reads[] = { |
| 22114 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22115 | "Content-Length: 0\r\n\r\n"), |
| 22116 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22117 | "Content-Length: 0\r\n\r\n"), |
| 22118 | }; |
| 22119 | StaticSocketDataProvider data2(mock_reads, mock_writes); |
| 22120 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22121 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 22122 | ssl2.expected_send_client_cert = true; |
| 22123 | ssl2.expected_client_cert = identity->certificate(); |
| 22124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 22125 | |
| 22126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22127 | |
| 22128 | // Start the first request. It succeeds after providing client certificates. |
| 22129 | TestCompletionCallback callback; |
| 22130 | auto trans = |
| 22131 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22132 | ASSERT_THAT(callback.GetResult(trans->Start(&request1, callback.callback(), |
| 22133 | NetLogWithSource())), |
| 22134 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 22135 | |
| 22136 | SSLCertRequestInfo* info = trans->GetResponseInfo()->cert_request_info.get(); |
| 22137 | ASSERT_TRUE(info); |
| 22138 | EXPECT_FALSE(info->is_proxy); |
| 22139 | EXPECT_EQ(info->host_and_port, cert_request_info->host_and_port); |
| 22140 | |
| 22141 | ASSERT_THAT(callback.GetResult(trans->RestartWithCertificate( |
| 22142 | identity->certificate(), identity->ssl_private_key(), |
| 22143 | callback.callback())), |
| 22144 | IsOk()); |
| 22145 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 22146 | |
| 22147 | // Make the second request. It completes without requesting client |
| 22148 | // certificates. |
| 22149 | trans = |
| 22150 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22151 | ASSERT_THAT(callback.GetResult(trans->Start(&request2, callback.callback(), |
| 22152 | NetLogWithSource())), |
| 22153 | IsOk()); |
| 22154 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 22155 | } |
| 22156 | |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 22157 | // Test for kPartitionConnectionsByNetworkIsolationKey. Runs 3 requests in |
| 22158 | // sequence with two different NetworkIsolationKeys, the first and last have the |
| 22159 | // same key, the second a different one. Checks that the requests are |
| 22160 | // partitioned across sockets as expected. |
| 22161 | TEST_F(HttpNetworkTransactionTest, NetworkIsolation) { |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 22162 | const SchemefulSite kSite1(GURL("http://origin1/")); |
| 22163 | const SchemefulSite kSite2(GURL("http://origin2/")); |
| 22164 | NetworkIsolationKey network_isolation_key1(kSite1, kSite1); |
| 22165 | NetworkIsolationKey network_isolation_key2(kSite2, kSite2); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 22166 | |
| 22167 | for (bool partition_connections : {false, true}) { |
| 22168 | SCOPED_TRACE(partition_connections); |
| 22169 | |
| 22170 | base::test::ScopedFeatureList feature_list; |
| 22171 | if (partition_connections) { |
| 22172 | feature_list.InitAndEnableFeature( |
| 22173 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22174 | } else { |
| 22175 | feature_list.InitAndDisableFeature( |
| 22176 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22177 | } |
| 22178 | |
| 22179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22180 | |
| 22181 | // Reads and writes for the unpartitioned case, where only one socket is |
| 22182 | // used. |
| 22183 | |
| 22184 | const MockWrite kUnpartitionedWrites[] = { |
| 22185 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22186 | "Host: foo.test\r\n" |
| 22187 | "Connection: keep-alive\r\n\r\n"), |
| 22188 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 22189 | "Host: foo.test\r\n" |
| 22190 | "Connection: keep-alive\r\n\r\n"), |
| 22191 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 22192 | "Host: foo.test\r\n" |
| 22193 | "Connection: keep-alive\r\n\r\n"), |
| 22194 | }; |
| 22195 | |
| 22196 | const MockRead kUnpartitionedReads[] = { |
| 22197 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22198 | "Connection: keep-alive\r\n" |
| 22199 | "Content-Length: 1\r\n\r\n" |
| 22200 | "1"), |
| 22201 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22202 | "Connection: keep-alive\r\n" |
| 22203 | "Content-Length: 1\r\n\r\n" |
| 22204 | "2"), |
| 22205 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22206 | "Connection: keep-alive\r\n" |
| 22207 | "Content-Length: 1\r\n\r\n" |
| 22208 | "3"), |
| 22209 | }; |
| 22210 | |
| 22211 | StaticSocketDataProvider unpartitioned_data(kUnpartitionedReads, |
| 22212 | kUnpartitionedWrites); |
| 22213 | |
| 22214 | // Reads and writes for the partitioned case, where two sockets are used. |
| 22215 | |
| 22216 | const MockWrite kPartitionedWrites1[] = { |
| 22217 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22218 | "Host: foo.test\r\n" |
| 22219 | "Connection: keep-alive\r\n\r\n"), |
| 22220 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 22221 | "Host: foo.test\r\n" |
| 22222 | "Connection: keep-alive\r\n\r\n"), |
| 22223 | }; |
| 22224 | |
| 22225 | const MockRead kPartitionedReads1[] = { |
| 22226 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22227 | "Connection: keep-alive\r\n" |
| 22228 | "Content-Length: 1\r\n\r\n" |
| 22229 | "1"), |
| 22230 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22231 | "Connection: keep-alive\r\n" |
| 22232 | "Content-Length: 1\r\n\r\n" |
| 22233 | "3"), |
| 22234 | }; |
| 22235 | |
| 22236 | const MockWrite kPartitionedWrites2[] = { |
| 22237 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 22238 | "Host: foo.test\r\n" |
| 22239 | "Connection: keep-alive\r\n\r\n"), |
| 22240 | }; |
| 22241 | |
| 22242 | const MockRead kPartitionedReads2[] = { |
| 22243 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22244 | "Connection: keep-alive\r\n" |
| 22245 | "Content-Length: 1\r\n\r\n" |
| 22246 | "2"), |
| 22247 | }; |
| 22248 | |
| 22249 | StaticSocketDataProvider partitioned_data1(kPartitionedReads1, |
| 22250 | kPartitionedWrites1); |
| 22251 | StaticSocketDataProvider partitioned_data2(kPartitionedReads2, |
| 22252 | kPartitionedWrites2); |
| 22253 | |
| 22254 | if (partition_connections) { |
| 22255 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 22256 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 22257 | } else { |
| 22258 | session_deps_.socket_factory->AddSocketDataProvider(&unpartitioned_data); |
| 22259 | } |
| 22260 | |
| 22261 | TestCompletionCallback callback; |
| 22262 | HttpRequestInfo request1; |
| 22263 | request1.method = "GET"; |
| 22264 | request1.url = GURL("http://foo.test/1"); |
| 22265 | request1.traffic_annotation = |
| 22266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22267 | request1.network_isolation_key = network_isolation_key1; |
| 22268 | auto trans1 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 22269 | session.get()); |
| 22270 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22271 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22272 | std::string response_data1; |
| 22273 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22274 | EXPECT_EQ("1", response_data1); |
| 22275 | trans1.reset(); |
| 22276 | |
| 22277 | HttpRequestInfo request2; |
| 22278 | request2.method = "GET"; |
| 22279 | request2.url = GURL("http://foo.test/2"); |
| 22280 | request2.traffic_annotation = |
| 22281 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22282 | request2.network_isolation_key = network_isolation_key2; |
| 22283 | auto trans2 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 22284 | session.get()); |
| 22285 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22286 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22287 | std::string response_data2; |
| 22288 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22289 | EXPECT_EQ("2", response_data2); |
| 22290 | trans2.reset(); |
| 22291 | |
| 22292 | HttpRequestInfo request3; |
| 22293 | request3.method = "GET"; |
| 22294 | request3.url = GURL("http://foo.test/3"); |
| 22295 | request3.traffic_annotation = |
| 22296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22297 | request3.network_isolation_key = network_isolation_key1; |
| 22298 | auto trans3 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 22299 | session.get()); |
| 22300 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22302 | std::string response_data3; |
| 22303 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22304 | EXPECT_EQ("3", response_data3); |
| 22305 | trans3.reset(); |
| 22306 | } |
| 22307 | } |
| 22308 | |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22309 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationH2) { |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 22310 | const SchemefulSite kSite1(GURL("http://origin1/")); |
| 22311 | const SchemefulSite kSite2(GURL("http://origin2/")); |
| 22312 | NetworkIsolationKey network_isolation_key1(kSite1, kSite1); |
| 22313 | NetworkIsolationKey network_isolation_key2(kSite2, kSite2); |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22314 | |
| 22315 | // Whether to use an H2 proxy. When false, uses HTTPS H2 requests without a |
| 22316 | // proxy, when true, uses HTTP requests over an H2 proxy. It's unnecessary to |
| 22317 | // test tunneled HTTPS over an H2 proxy, since that path sets up H2 sessions |
| 22318 | // the same way as the HTTP over H2 proxy case. |
| 22319 | for (bool use_proxy : {false, true}) { |
| 22320 | SCOPED_TRACE(use_proxy); |
| 22321 | if (use_proxy) { |
| 22322 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 22323 | ConfiguredProxyResolutionService::CreateFixedFromPacResult( |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22324 | "HTTPS proxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22325 | } else { |
| 22326 | session_deps_.proxy_resolution_service = |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 22327 | ConfiguredProxyResolutionService::CreateDirect(); |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 22328 | } |
| 22329 | const char* url1 = nullptr; |
| 22330 | const char* url2 = nullptr; |
| 22331 | const char* url3 = nullptr; |
| 22332 | if (use_proxy) { |
| 22333 | url1 = "http://foo.test/1"; |
| 22334 | url2 = "http://foo.test/2"; |
| 22335 | url3 = "http://foo.test/3"; |
| 22336 | } else { |
| 22337 | url1 = "https://foo.test/1"; |
| 22338 | url2 = "https://foo.test/2"; |
| 22339 | url3 = "https://foo.test/3"; |
| 22340 | } |
| 22341 | |
| 22342 | for (bool partition_connections : {false, true}) { |
| 22343 | SCOPED_TRACE(partition_connections); |
| 22344 | |
| 22345 | base::test::ScopedFeatureList feature_list; |
| 22346 | if (partition_connections) { |
| 22347 | feature_list.InitAndEnableFeature( |
| 22348 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22349 | } else { |
| 22350 | feature_list.InitAndDisableFeature( |
| 22351 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22352 | } |
| 22353 | |
| 22354 | std::unique_ptr<HttpNetworkSession> session( |
| 22355 | CreateSession(&session_deps_)); |
| 22356 | |
| 22357 | // Reads and writes for the unpartitioned case, where only one socket is |
| 22358 | // used. |
| 22359 | |
| 22360 | SpdyTestUtil spdy_util; |
| 22361 | spdy::SpdySerializedFrame unpartitioned_req1( |
| 22362 | spdy_util.ConstructSpdyGet(url1, 1, LOWEST)); |
| 22363 | spdy::SpdySerializedFrame unpartitioned_response1( |
| 22364 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 22365 | spdy::SpdySerializedFrame unpartitioned_body1( |
| 22366 | spdy_util.ConstructSpdyDataFrame(1, "1", true)); |
| 22367 | spdy_util.UpdateWithStreamDestruction(1); |
| 22368 | |
| 22369 | spdy::SpdySerializedFrame unpartitioned_req2( |
| 22370 | spdy_util.ConstructSpdyGet(url2, 3, LOWEST)); |
| 22371 | spdy::SpdySerializedFrame unpartitioned_response2( |
| 22372 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 22373 | spdy::SpdySerializedFrame unpartitioned_body2( |
| 22374 | spdy_util.ConstructSpdyDataFrame(3, "2", true)); |
| 22375 | spdy_util.UpdateWithStreamDestruction(3); |
| 22376 | |
| 22377 | spdy::SpdySerializedFrame unpartitioned_req3( |
| 22378 | spdy_util.ConstructSpdyGet(url3, 5, LOWEST)); |
| 22379 | spdy::SpdySerializedFrame unpartitioned_response3( |
| 22380 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 5)); |
| 22381 | spdy::SpdySerializedFrame unpartitioned_body3( |
| 22382 | spdy_util.ConstructSpdyDataFrame(5, "3", true)); |
| 22383 | |
| 22384 | const MockWrite kUnpartitionedWrites[] = { |
| 22385 | CreateMockWrite(unpartitioned_req1, 0), |
| 22386 | CreateMockWrite(unpartitioned_req2, 3), |
| 22387 | CreateMockWrite(unpartitioned_req3, 6), |
| 22388 | }; |
| 22389 | |
| 22390 | const MockRead kUnpartitionedReads[] = { |
| 22391 | CreateMockRead(unpartitioned_response1, 1), |
| 22392 | CreateMockRead(unpartitioned_body1, 2), |
| 22393 | CreateMockRead(unpartitioned_response2, 4), |
| 22394 | CreateMockRead(unpartitioned_body2, 5), |
| 22395 | CreateMockRead(unpartitioned_response3, 7), |
| 22396 | CreateMockRead(unpartitioned_body3, 8), |
| 22397 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 9), |
| 22398 | }; |
| 22399 | |
| 22400 | SequencedSocketData unpartitioned_data(kUnpartitionedReads, |
| 22401 | kUnpartitionedWrites); |
| 22402 | |
| 22403 | // Reads and writes for the partitioned case, where two sockets are used. |
| 22404 | |
| 22405 | SpdyTestUtil spdy_util2; |
| 22406 | spdy::SpdySerializedFrame partitioned_req1( |
| 22407 | spdy_util2.ConstructSpdyGet(url1, 1, LOWEST)); |
| 22408 | spdy::SpdySerializedFrame partitioned_response1( |
| 22409 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 22410 | spdy::SpdySerializedFrame partitioned_body1( |
| 22411 | spdy_util2.ConstructSpdyDataFrame(1, "1", true)); |
| 22412 | spdy_util2.UpdateWithStreamDestruction(1); |
| 22413 | |
| 22414 | spdy::SpdySerializedFrame partitioned_req3( |
| 22415 | spdy_util2.ConstructSpdyGet(url3, 3, LOWEST)); |
| 22416 | spdy::SpdySerializedFrame partitioned_response3( |
| 22417 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 22418 | spdy::SpdySerializedFrame partitioned_body3( |
| 22419 | spdy_util2.ConstructSpdyDataFrame(3, "3", true)); |
| 22420 | |
| 22421 | const MockWrite kPartitionedWrites1[] = { |
| 22422 | CreateMockWrite(partitioned_req1, 0), |
| 22423 | CreateMockWrite(partitioned_req3, 3), |
| 22424 | }; |
| 22425 | |
| 22426 | const MockRead kPartitionedReads1[] = { |
| 22427 | CreateMockRead(partitioned_response1, 1), |
| 22428 | CreateMockRead(partitioned_body1, 2), |
| 22429 | CreateMockRead(partitioned_response3, 4), |
| 22430 | CreateMockRead(partitioned_body3, 5), |
| 22431 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
| 22432 | }; |
| 22433 | |
| 22434 | SpdyTestUtil spdy_util3; |
| 22435 | spdy::SpdySerializedFrame partitioned_req2( |
| 22436 | spdy_util3.ConstructSpdyGet(url2, 1, LOWEST)); |
| 22437 | spdy::SpdySerializedFrame partitioned_response2( |
| 22438 | spdy_util3.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 22439 | spdy::SpdySerializedFrame partitioned_body2( |
| 22440 | spdy_util3.ConstructSpdyDataFrame(1, "2", true)); |
| 22441 | |
| 22442 | const MockWrite kPartitionedWrites2[] = { |
| 22443 | CreateMockWrite(partitioned_req2, 0), |
| 22444 | }; |
| 22445 | |
| 22446 | const MockRead kPartitionedReads2[] = { |
| 22447 | CreateMockRead(partitioned_response2, 1), |
| 22448 | CreateMockRead(partitioned_body2, 2), |
| 22449 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
| 22450 | }; |
| 22451 | |
| 22452 | SequencedSocketData partitioned_data1(kPartitionedReads1, |
| 22453 | kPartitionedWrites1); |
| 22454 | SequencedSocketData partitioned_data2(kPartitionedReads2, |
| 22455 | kPartitionedWrites2); |
| 22456 | |
| 22457 | // No need to segment SSLDataProviders by whether or not partitioning is |
| 22458 | // enabled. |
| 22459 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 22460 | ssl_data1.next_proto = kProtoHTTP2; |
| 22461 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 22462 | ssl_data2.next_proto = kProtoHTTP2; |
| 22463 | |
| 22464 | if (partition_connections) { |
| 22465 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 22466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 22467 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 22468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 22469 | } else { |
| 22470 | session_deps_.socket_factory->AddSocketDataProvider( |
| 22471 | &unpartitioned_data); |
| 22472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 22473 | } |
| 22474 | |
| 22475 | TestCompletionCallback callback; |
| 22476 | HttpRequestInfo request1; |
| 22477 | request1.method = "GET"; |
| 22478 | request1.url = GURL(url1); |
| 22479 | request1.traffic_annotation = |
| 22480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22481 | request1.network_isolation_key = network_isolation_key1; |
| 22482 | auto trans1 = |
| 22483 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 22484 | int rv = |
| 22485 | trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22486 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22487 | std::string response_data1; |
| 22488 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22489 | EXPECT_EQ("1", response_data1); |
| 22490 | trans1.reset(); |
| 22491 | |
| 22492 | HttpRequestInfo request2; |
| 22493 | request2.method = "GET"; |
| 22494 | request2.url = GURL(url2); |
| 22495 | request2.traffic_annotation = |
| 22496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22497 | request2.network_isolation_key = network_isolation_key2; |
| 22498 | auto trans2 = |
| 22499 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 22500 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22501 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22502 | std::string response_data2; |
| 22503 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22504 | EXPECT_EQ("2", response_data2); |
| 22505 | trans2.reset(); |
| 22506 | |
| 22507 | HttpRequestInfo request3; |
| 22508 | request3.method = "GET"; |
| 22509 | request3.url = GURL(url3); |
| 22510 | request3.traffic_annotation = |
| 22511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22512 | request3.network_isolation_key = network_isolation_key1; |
| 22513 | auto trans3 = |
| 22514 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 22515 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22516 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22517 | std::string response_data3; |
| 22518 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22519 | EXPECT_EQ("3", response_data3); |
| 22520 | trans3.reset(); |
| 22521 | } |
| 22522 | } |
| 22523 | } |
| 22524 | |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 22525 | // Preconnect two sockets with different NetworkIsolationKeys when |
| 22526 | // features::kPartitionConnectionsByNetworkIsolationKey is enabled. Then issue a |
| 22527 | // request and make sure the correct socket is used. Loops three times, |
| 22528 | // expecting to use the first preconnect, second preconnect, and neither. |
| 22529 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationPreconnect) { |
| 22530 | base::test::ScopedFeatureList feature_list; |
| 22531 | feature_list.InitAndEnableFeature( |
| 22532 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 22533 | |
| 22534 | enum class TestCase { |
| 22535 | kUseFirstPreconnect, |
| 22536 | kUseSecondPreconnect, |
| 22537 | kDontUsePreconnect, |
| 22538 | }; |
| 22539 | |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 22540 | const SchemefulSite kSite1(GURL("http://origin1/")); |
| 22541 | const SchemefulSite kSite2(GURL("http://origin2/")); |
| 22542 | const SchemefulSite kSite3(GURL("http://origin3/")); |
| 22543 | NetworkIsolationKey preconnect1_isolation_key(kSite1, kSite1); |
| 22544 | NetworkIsolationKey preconnect2_isolation_key(kSite2, kSite2); |
| 22545 | NetworkIsolationKey not_preconnected_isolation_key(kSite3, kSite3); |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 22546 | |
| 22547 | // Test that only preconnects with |
| 22548 | for (TestCase test_case : |
| 22549 | {TestCase::kUseFirstPreconnect, TestCase::kUseSecondPreconnect, |
| 22550 | TestCase::kDontUsePreconnect}) { |
| 22551 | SpdySessionDependencies session_deps; |
| 22552 | // Make DNS lookups completely synchronously, so preconnects complete |
| 22553 | // immediately. |
| 22554 | session_deps.host_resolver->set_synchronous_mode(true); |
| 22555 | |
| 22556 | const MockWrite kMockWrites[] = { |
| 22557 | MockWrite(ASYNC, 0, |
| 22558 | "GET / HTTP/1.1\r\n" |
| 22559 | "Host: www.foo.com\r\n" |
| 22560 | "Connection: keep-alive\r\n\r\n"), |
| 22561 | }; |
| 22562 | |
| 22563 | const MockRead kMockReads[] = { |
| 22564 | MockRead(ASYNC, 1, |
| 22565 | "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n" |
| 22566 | "hello"), |
| 22567 | }; |
| 22568 | |
| 22569 | // Used for the socket that will actually be used, which may or may not be |
| 22570 | // one of the preconnects |
| 22571 | SequencedSocketData used_socket_data(MockConnect(SYNCHRONOUS, OK), |
| 22572 | kMockReads, kMockWrites); |
| 22573 | |
| 22574 | // Used for the preconnects that won't actually be used. |
| 22575 | SequencedSocketData preconnect1_data(MockConnect(SYNCHRONOUS, OK), |
| 22576 | base::span<const MockRead>(), |
| 22577 | base::span<const MockWrite>()); |
| 22578 | SequencedSocketData preconnect2_data(MockConnect(SYNCHRONOUS, OK), |
| 22579 | base::span<const MockRead>(), |
| 22580 | base::span<const MockWrite>()); |
| 22581 | |
| 22582 | NetworkIsolationKey network_isolation_key_for_request; |
| 22583 | |
| 22584 | switch (test_case) { |
| 22585 | case TestCase::kUseFirstPreconnect: |
| 22586 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 22587 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 22588 | network_isolation_key_for_request = preconnect1_isolation_key; |
| 22589 | break; |
| 22590 | case TestCase::kUseSecondPreconnect: |
| 22591 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 22592 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 22593 | network_isolation_key_for_request = preconnect2_isolation_key; |
| 22594 | break; |
| 22595 | case TestCase::kDontUsePreconnect: |
| 22596 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 22597 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 22598 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 22599 | network_isolation_key_for_request = not_preconnected_isolation_key; |
| 22600 | break; |
| 22601 | } |
| 22602 | |
| 22603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 22604 | |
| 22605 | // Preconnect sockets. |
| 22606 | HttpRequestInfo request; |
| 22607 | request.method = "GET"; |
| 22608 | request.url = GURL("http://www.foo.com/"); |
| 22609 | request.traffic_annotation = |
| 22610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22611 | |
| 22612 | request.network_isolation_key = preconnect1_isolation_key; |
| 22613 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 22614 | |
| 22615 | request.network_isolation_key = preconnect2_isolation_key; |
| 22616 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 22617 | |
| 22618 | request.network_isolation_key = network_isolation_key_for_request; |
| 22619 | |
| 22620 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 22621 | |
| 22622 | // Make the request. |
| 22623 | TestCompletionCallback callback; |
| 22624 | |
| 22625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 22626 | |
| 22627 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 22628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22629 | |
| 22630 | rv = callback.WaitForResult(); |
| 22631 | EXPECT_THAT(rv, IsOk()); |
| 22632 | |
| 22633 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 22634 | ASSERT_TRUE(response); |
| 22635 | ASSERT_TRUE(response->headers); |
| 22636 | EXPECT_EQ(200, response->headers->response_code()); |
| 22637 | |
| 22638 | std::string response_data; |
| 22639 | rv = ReadTransaction(&trans, &response_data); |
| 22640 | EXPECT_THAT(rv, IsOk()); |
| 22641 | EXPECT_EQ("hello", response_data); |
| 22642 | |
| 22643 | if (test_case != TestCase::kDontUsePreconnect) { |
| 22644 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 22645 | } else { |
| 22646 | EXPECT_EQ(3, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 22647 | } |
| 22648 | } |
| 22649 | } |
| 22650 | |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22651 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 22652 | // cache is isolated. |
| 22653 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSL) { |
| 22654 | base::test::ScopedFeatureList feature_list; |
| 22655 | feature_list.InitWithFeatures( |
| 22656 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 22657 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 22658 | {}); |
| 22659 | |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 22660 | const SchemefulSite kSite1(GURL("http://origin1/")); |
| 22661 | const SchemefulSite kSite2(GURL("http://origin2/")); |
| 22662 | const NetworkIsolationKey kNetworkIsolationKey1(kSite1, kSite1); |
| 22663 | const NetworkIsolationKey kNetworkIsolationKey2(kSite2, kSite2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22665 | |
| 22666 | // The server always sends Connection: close, so each request goes over a |
| 22667 | // distinct socket. |
| 22668 | |
| 22669 | const MockWrite kWrites1[] = { |
| 22670 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22671 | "Host: foo.test\r\n" |
| 22672 | "Connection: keep-alive\r\n\r\n")}; |
| 22673 | |
| 22674 | const MockRead kReads1[] = { |
| 22675 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22676 | "Connection: close\r\n" |
| 22677 | "Content-Length: 1\r\n\r\n" |
| 22678 | "1")}; |
| 22679 | |
| 22680 | const MockWrite kWrites2[] = { |
| 22681 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 22682 | "Host: foo.test\r\n" |
| 22683 | "Connection: keep-alive\r\n\r\n")}; |
| 22684 | |
| 22685 | const MockRead kReads2[] = { |
| 22686 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22687 | "Connection: close\r\n" |
| 22688 | "Content-Length: 1\r\n\r\n" |
| 22689 | "2")}; |
| 22690 | |
| 22691 | const MockWrite kWrites3[] = { |
| 22692 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 22693 | "Host: foo.test\r\n" |
| 22694 | "Connection: keep-alive\r\n\r\n")}; |
| 22695 | |
| 22696 | const MockRead kReads3[] = { |
| 22697 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22698 | "Connection: close\r\n" |
| 22699 | "Content-Length: 1\r\n\r\n" |
| 22700 | "3")}; |
| 22701 | |
| 22702 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 22703 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 22704 | StaticSocketDataProvider data3(kReads3, kWrites3); |
| 22705 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22706 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22707 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 22708 | |
| 22709 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 22710 | ssl_data1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22711 | ssl_data1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22712 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 22713 | ssl_data2.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22714 | ssl_data2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 22715 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
| 22716 | ssl_data3.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22717 | ssl_data3.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 22719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 22720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
| 22721 | |
| 22722 | TestCompletionCallback callback; |
| 22723 | HttpRequestInfo request1; |
| 22724 | request1.method = "GET"; |
| 22725 | request1.url = GURL("https://foo.test/1"); |
| 22726 | request1.traffic_annotation = |
| 22727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22728 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 22729 | auto trans1 = |
| 22730 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22731 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22732 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22733 | std::string response_data1; |
| 22734 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22735 | EXPECT_EQ("1", response_data1); |
| 22736 | trans1.reset(); |
| 22737 | |
| 22738 | HttpRequestInfo request2; |
| 22739 | request2.method = "GET"; |
| 22740 | request2.url = GURL("https://foo.test/2"); |
| 22741 | request2.traffic_annotation = |
| 22742 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22743 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 22744 | auto trans2 = |
| 22745 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22746 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22747 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22748 | std::string response_data2; |
| 22749 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22750 | EXPECT_EQ("2", response_data2); |
| 22751 | trans2.reset(); |
| 22752 | |
| 22753 | HttpRequestInfo request3; |
| 22754 | request3.method = "GET"; |
| 22755 | request3.url = GURL("https://foo.test/3"); |
| 22756 | request3.traffic_annotation = |
| 22757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22758 | request3.network_isolation_key = kNetworkIsolationKey1; |
| 22759 | auto trans3 = |
| 22760 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22761 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22762 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22763 | std::string response_data3; |
| 22764 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22765 | EXPECT_EQ("3", response_data3); |
| 22766 | trans3.reset(); |
| 22767 | } |
| 22768 | |
| 22769 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 22770 | // cache is isolated, for both origins and proxies. |
| 22771 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSLProxy) { |
| 22772 | base::test::ScopedFeatureList feature_list; |
| 22773 | feature_list.InitWithFeatures( |
| 22774 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 22775 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 22776 | {}); |
| 22777 | |
Nicolas Arciniega | d2013f9 | 2020-02-07 23:00:56 | [diff] [blame] | 22778 | session_deps_.proxy_resolution_service = |
| 22779 | ConfiguredProxyResolutionService::CreateFixed( |
| 22780 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22781 | |
Matt Menke | 4807a9a | 2020-11-21 00:14:41 | [diff] [blame^] | 22782 | const SchemefulSite kSite1(GURL("http://origin1/")); |
| 22783 | const SchemefulSite kSite2(GURL("http://origin2/")); |
| 22784 | const NetworkIsolationKey kNetworkIsolationKey1(kSite1, kSite1); |
| 22785 | const NetworkIsolationKey kNetworkIsolationKey2(kSite2, kSite2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 22786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 22787 | |
| 22788 | // Make both a tunneled and non-tunneled request. |
| 22789 | HttpRequestInfo request1; |
| 22790 | request1.method = "GET"; |
| 22791 | request1.url = GURL("https://foo.test/1"); |
| 22792 | request1.traffic_annotation = |
| 22793 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22794 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 22795 | |
| 22796 | HttpRequestInfo request2; |
| 22797 | request2.method = "GET"; |
| 22798 | request2.url = GURL("http://foo.test/2"); |
| 22799 | request2.traffic_annotation = |
| 22800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22801 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 22802 | |
| 22803 | const MockWrite kWrites1[] = { |
| 22804 | MockWrite("CONNECT foo.test:443 HTTP/1.1\r\n" |
| 22805 | "Host: foo.test:443\r\n" |
| 22806 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 22807 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22808 | "Host: foo.test\r\n" |
| 22809 | "Connection: keep-alive\r\n\r\n")}; |
| 22810 | |
| 22811 | const MockRead kReads1[] = { |
| 22812 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 22813 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22814 | "Connection: close\r\n" |
| 22815 | "Content-Length: 1\r\n\r\n" |
| 22816 | "1")}; |
| 22817 | |
| 22818 | const MockWrite kWrites2[] = { |
| 22819 | MockWrite("GET http://foo.test/2 HTTP/1.1\r\n" |
| 22820 | "Host: foo.test\r\n" |
| 22821 | "Proxy-Connection: keep-alive\r\n\r\n")}; |
| 22822 | |
| 22823 | const MockRead kReads2[] = { |
| 22824 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22825 | "Connection: close\r\n" |
| 22826 | "Content-Length: 1\r\n\r\n" |
| 22827 | "2")}; |
| 22828 | |
| 22829 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 22830 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 22831 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22832 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22833 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22834 | |
| 22835 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 22836 | ssl_proxy1.expected_host_and_port = HostPortPair("myproxy", 70); |
| 22837 | ssl_proxy1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22838 | SSLSocketDataProvider ssl_origin1(ASYNC, OK); |
| 22839 | ssl_origin1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 22840 | ssl_origin1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 22841 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 22842 | ssl_proxy2.expected_host_and_port = HostPortPair("myproxy", 70); |
| 22843 | ssl_proxy2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 22844 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 22845 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 22846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 22847 | |
| 22848 | TestCompletionCallback callback; |
| 22849 | auto trans1 = |
| 22850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22851 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22852 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22853 | std::string response_data1; |
| 22854 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22855 | EXPECT_EQ("1", response_data1); |
| 22856 | trans1.reset(); |
| 22857 | |
| 22858 | auto trans2 = |
| 22859 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22860 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22861 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22862 | std::string response_data2; |
| 22863 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22864 | EXPECT_EQ("2", response_data2); |
| 22865 | trans2.reset(); |
| 22866 | } |
| 22867 | |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22868 | // Test that SSLConfig changes from SSLConfigService are picked up even when |
| 22869 | // there are live sockets. |
| 22870 | TEST_F(HttpNetworkTransactionTest, SSLConfigChanged) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22871 | SSLContextConfig ssl_context_config; |
| 22872 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22873 | auto ssl_config_service = |
| 22874 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22875 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 22876 | |
| 22877 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 22878 | |
| 22879 | // Make three requests. Between the second and third, the SSL config will |
| 22880 | // change. |
| 22881 | HttpRequestInfo request1; |
| 22882 | request1.method = "GET"; |
| 22883 | request1.url = GURL("https://foo.test/1"); |
| 22884 | request1.traffic_annotation = |
| 22885 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22886 | |
| 22887 | HttpRequestInfo request2; |
| 22888 | request2.method = "GET"; |
| 22889 | request2.url = GURL("https://foo.test/2"); |
| 22890 | request2.traffic_annotation = |
| 22891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22892 | |
| 22893 | HttpRequestInfo request3; |
| 22894 | request3.method = "GET"; |
| 22895 | request3.url = GURL("https://foo.test/3"); |
| 22896 | request3.traffic_annotation = |
| 22897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22898 | |
| 22899 | const MockWrite kWrites1[] = { |
| 22900 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 22901 | "Host: foo.test\r\n" |
| 22902 | "Connection: keep-alive\r\n\r\n"), |
| 22903 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 22904 | "Host: foo.test\r\n" |
| 22905 | "Connection: keep-alive\r\n\r\n"), |
| 22906 | }; |
| 22907 | |
| 22908 | const MockRead kReads1[] = { |
| 22909 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22910 | "Connection: keep-alive\r\n" |
| 22911 | "Content-Length: 1\r\n\r\n" |
| 22912 | "1"), |
| 22913 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22914 | "Connection: keep-alive\r\n" |
| 22915 | "Content-Length: 1\r\n\r\n" |
| 22916 | "2"), |
| 22917 | }; |
| 22918 | |
| 22919 | // The third request goes on a different socket because the SSL config has |
| 22920 | // changed. |
| 22921 | const MockWrite kWrites2[] = { |
| 22922 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 22923 | "Host: foo.test\r\n" |
| 22924 | "Connection: keep-alive\r\n\r\n")}; |
| 22925 | |
| 22926 | const MockRead kReads2[] = { |
| 22927 | MockRead("HTTP/1.1 200 OK\r\n" |
| 22928 | "Connection: keep-alive\r\n" |
| 22929 | "Content-Length: 1\r\n\r\n" |
| 22930 | "3")}; |
| 22931 | |
| 22932 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 22933 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 22934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 22935 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 22936 | |
| 22937 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 22938 | ssl1.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22939 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 22940 | ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 22941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 22942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 22943 | |
| 22944 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22945 | |
| 22946 | TestCompletionCallback callback; |
| 22947 | auto trans1 = |
| 22948 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22949 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 22950 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22951 | std::string response_data1; |
| 22952 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 22953 | EXPECT_EQ("1", response_data1); |
| 22954 | trans1.reset(); |
| 22955 | |
| 22956 | auto trans2 = |
| 22957 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22958 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 22959 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22960 | std::string response_data2; |
| 22961 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 22962 | EXPECT_EQ("2", response_data2); |
| 22963 | trans2.reset(); |
| 22964 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22965 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 22966 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22967 | |
| 22968 | auto trans3 = |
| 22969 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22970 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 22971 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 22972 | std::string response_data3; |
| 22973 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 22974 | EXPECT_EQ("3", response_data3); |
| 22975 | trans3.reset(); |
| 22976 | } |
| 22977 | |
| 22978 | TEST_F(HttpNetworkTransactionTest, SSLConfigChangedPendingConnect) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22979 | SSLContextConfig ssl_context_config; |
| 22980 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22981 | auto ssl_config_service = |
| 22982 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22983 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 22984 | |
| 22985 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 22986 | |
| 22987 | HttpRequestInfo request; |
| 22988 | request.method = "GET"; |
| 22989 | request.url = GURL("https://foo.test/1"); |
| 22990 | request.traffic_annotation = |
| 22991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22992 | |
| 22993 | // Make a socket which never connects. |
| 22994 | StaticSocketDataProvider data({}, {}); |
| 22995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 22996 | SSLSocketDataProvider ssl_data(SYNCHRONOUS, ERR_IO_PENDING); |
| 22997 | ssl_data.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22998 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
| 22999 | |
| 23000 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 23001 | |
| 23002 | TestCompletionCallback callback; |
| 23003 | auto trans = |
| 23004 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23005 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 23006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 23007 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 23008 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 23009 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 23010 | |
| 23011 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NETWORK_CHANGED)); |
| 23012 | } |
| 23013 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 23014 | // Test that HttpNetworkTransaction correctly handles existing sockets when the |
| 23015 | // server requests a client certificate post-handshake (via a TLS |
| 23016 | // renegotiation). This is a regression test for https://crbug.com/829184. |
| 23017 | TEST_F(HttpNetworkTransactionTest, PostHandshakeClientCertWithSockets) { |
| 23018 | const MutableNetworkTrafficAnnotationTag kTrafficAnnotation( |
| 23019 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 23020 | |
| 23021 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 23022 | cert_request_info->host_and_port = HostPortPair("foo.test", 443); |
| 23023 | |
| 23024 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 23025 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 23026 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 23027 | ASSERT_TRUE(identity); |
| 23028 | |
| 23029 | // This test will make several requests so that, when the client certificate |
| 23030 | // request comes in, we have a socket in use, an idle socket, and a socket for |
| 23031 | // an unrelated host. |
| 23032 | // |
| 23033 | // First, two long-lived requests which do not complete until after the client |
| 23034 | // certificate request. This arranges for sockets to be in use during the |
| 23035 | // request. They should not be interrupted. |
| 23036 | HttpRequestInfo request_long_lived; |
| 23037 | request_long_lived.method = "GET"; |
| 23038 | request_long_lived.url = GURL("https://foo.test/long-lived"); |
| 23039 | request_long_lived.traffic_annotation = kTrafficAnnotation; |
| 23040 | |
| 23041 | HttpRequestInfo request_long_lived_bar; |
| 23042 | request_long_lived_bar.method = "GET"; |
| 23043 | request_long_lived_bar.url = GURL("https://bar.test/long-lived"); |
| 23044 | request_long_lived_bar.traffic_annotation = kTrafficAnnotation; |
| 23045 | |
| 23046 | // Next, make a request that needs client certificates. |
| 23047 | HttpRequestInfo request_auth; |
| 23048 | request_auth.method = "GET"; |
| 23049 | request_auth.url = GURL("https://foo.test/auth"); |
| 23050 | request_auth.traffic_annotation = kTrafficAnnotation; |
| 23051 | |
| 23052 | // Before responding to the challenge, make a request to an unauthenticated |
| 23053 | // endpoint. This will result in an idle socket when the client certificate |
| 23054 | // challenge is resolved. |
| 23055 | HttpRequestInfo request_unauth; |
| 23056 | request_unauth.method = "GET"; |
| 23057 | request_unauth.url = GURL("https://foo.test/unauth"); |
| 23058 | request_unauth.traffic_annotation = kTrafficAnnotation; |
| 23059 | |
| 23060 | // After all the preceding requests complete, end with two additional requests |
| 23061 | // to ensure pre-authentication foo.test sockets are not used and bar.test |
| 23062 | // sockets are unaffected. |
| 23063 | HttpRequestInfo request_post_auth; |
| 23064 | request_post_auth.method = "GET"; |
| 23065 | request_post_auth.url = GURL("https://foo.test/post-auth"); |
| 23066 | request_post_auth.traffic_annotation = kTrafficAnnotation; |
| 23067 | |
| 23068 | HttpRequestInfo request_post_auth_bar; |
| 23069 | request_post_auth_bar.method = "GET"; |
| 23070 | request_post_auth_bar.url = GURL("https://bar.test/post-auth"); |
| 23071 | request_post_auth_bar.traffic_annotation = kTrafficAnnotation; |
| 23072 | |
| 23073 | // The sockets for /long-lived and /unauth complete their request but are |
| 23074 | // not allocated for /post-auth or /retry because SSL state has since changed. |
| 23075 | const MockWrite kLongLivedWrites[] = { |
| 23076 | MockWrite(ASYNC, 0, |
| 23077 | "GET /long-lived HTTP/1.1\r\n" |
| 23078 | "Host: foo.test\r\n" |
| 23079 | "Connection: keep-alive\r\n\r\n"), |
| 23080 | }; |
| 23081 | const MockRead kLongLivedReads[] = { |
| 23082 | // Pause so /long-lived completes after the client presents client |
| 23083 | // certificates. |
| 23084 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 23085 | MockRead(ASYNC, 2, |
| 23086 | "HTTP/1.1 200 OK\r\n" |
| 23087 | "Connection: keep-alive\r\n" |
| 23088 | "Content-Length: 10\r\n\r\n" |
| 23089 | "long-lived"), |
| 23090 | }; |
| 23091 | SequencedSocketData data_long_lived(kLongLivedReads, kLongLivedWrites); |
| 23092 | SSLSocketDataProvider ssl_long_lived(ASYNC, OK); |
| 23093 | session_deps_.socket_factory->AddSocketDataProvider(&data_long_lived); |
| 23094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_long_lived); |
| 23095 | |
| 23096 | // Requests for bar.test should be unaffected by foo.test and get allocated |
| 23097 | // a single socket. |
| 23098 | const MockWrite kBarWrites[] = { |
| 23099 | MockWrite(ASYNC, 0, |
| 23100 | "GET /long-lived HTTP/1.1\r\n" |
| 23101 | "Host: bar.test\r\n" |
| 23102 | "Connection: keep-alive\r\n\r\n"), |
| 23103 | MockWrite(ASYNC, 3, |
| 23104 | "GET /post-auth HTTP/1.1\r\n" |
| 23105 | "Host: bar.test\r\n" |
| 23106 | "Connection: keep-alive\r\n\r\n"), |
| 23107 | }; |
| 23108 | const MockRead kBarReads[] = { |
| 23109 | // Pause on /long-lived so it completes after foo.test's authentication. |
| 23110 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 23111 | MockRead(ASYNC, 2, |
| 23112 | "HTTP/1.1 200 OK\r\n" |
| 23113 | "Connection: keep-alive\r\n" |
| 23114 | "Content-Length: 10\r\n\r\n" |
| 23115 | "long-lived"), |
| 23116 | MockRead(ASYNC, 4, |
| 23117 | "HTTP/1.1 200 OK\r\n" |
| 23118 | "Connection: keep-alive\r\n" |
| 23119 | "Content-Length: 9\r\n\r\n" |
| 23120 | "post-auth"), |
| 23121 | }; |
| 23122 | SequencedSocketData data_bar(kBarReads, kBarWrites); |
| 23123 | SSLSocketDataProvider ssl_bar(ASYNC, OK); |
| 23124 | session_deps_.socket_factory->AddSocketDataProvider(&data_bar); |
| 23125 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bar); |
| 23126 | |
| 23127 | // Requesting /auth results in a post-handshake client certificate challenge. |
| 23128 | const MockWrite kAuthWrites[] = { |
| 23129 | MockWrite(ASYNC, 0, |
| 23130 | "GET /auth HTTP/1.1\r\n" |
| 23131 | "Host: foo.test\r\n" |
| 23132 | "Connection: keep-alive\r\n\r\n"), |
| 23133 | }; |
| 23134 | const MockRead kAuthReads[] = { |
| 23135 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED, 1), |
| 23136 | }; |
| 23137 | SequencedSocketData data_auth(kAuthReads, kAuthWrites); |
| 23138 | SSLSocketDataProvider ssl_auth(ASYNC, OK); |
| 23139 | ssl_auth.cert_request_info = cert_request_info.get(); |
| 23140 | session_deps_.socket_factory->AddSocketDataProvider(&data_auth); |
| 23141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_auth); |
| 23142 | |
| 23143 | // Requesting /unauth completes. |
| 23144 | const MockWrite kUnauthWrites[] = { |
| 23145 | MockWrite(ASYNC, 0, |
| 23146 | "GET /unauth HTTP/1.1\r\n" |
| 23147 | "Host: foo.test\r\n" |
| 23148 | "Connection: keep-alive\r\n\r\n"), |
| 23149 | }; |
| 23150 | const MockRead kUnauthReads[] = { |
| 23151 | MockRead(ASYNC, 1, |
| 23152 | "HTTP/1.1 200 OK\r\n" |
| 23153 | "Connection: keep-alive\r\n" |
| 23154 | "Content-Length: 6\r\n\r\n" |
| 23155 | "unauth"), |
| 23156 | }; |
| 23157 | SequencedSocketData data_unauth(kUnauthReads, kUnauthWrites); |
| 23158 | SSLSocketDataProvider ssl_unauth(ASYNC, OK); |
| 23159 | session_deps_.socket_factory->AddSocketDataProvider(&data_unauth); |
| 23160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_unauth); |
| 23161 | |
| 23162 | // When the client certificate is selected, /auth is retried on a new |
| 23163 | // connection. In particular, it should not be retried on |data_unauth|, |
| 23164 | // which would not honor the new client certificate configuration. |
| 23165 | const MockWrite kRetryWrites[] = { |
| 23166 | MockWrite(ASYNC, 0, |
| 23167 | "GET /auth HTTP/1.1\r\n" |
| 23168 | "Host: foo.test\r\n" |
| 23169 | "Connection: keep-alive\r\n\r\n"), |
| 23170 | }; |
| 23171 | const MockRead kRetryReads[] = { |
| 23172 | MockRead(ASYNC, 1, |
| 23173 | "HTTP/1.1 200 OK\r\n" |
| 23174 | // Close the connection so we test that /post-auth is not |
| 23175 | // allocated to |data_unauth| or |data_long_lived|. |
| 23176 | "Connection: close\r\n" |
| 23177 | "Content-Length: 4\r\n\r\n" |
| 23178 | "auth"), |
| 23179 | }; |
| 23180 | SequencedSocketData data_retry(kRetryReads, kRetryWrites); |
| 23181 | SSLSocketDataProvider ssl_retry(ASYNC, OK); |
| 23182 | ssl_retry.expected_send_client_cert = true; |
| 23183 | ssl_retry.expected_client_cert = identity->certificate(); |
| 23184 | session_deps_.socket_factory->AddSocketDataProvider(&data_retry); |
| 23185 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_retry); |
| 23186 | |
| 23187 | // /post-auth gets its own socket. |
| 23188 | const MockWrite kPostAuthWrites[] = { |
| 23189 | MockWrite(ASYNC, 0, |
| 23190 | "GET /post-auth HTTP/1.1\r\n" |
| 23191 | "Host: foo.test\r\n" |
| 23192 | "Connection: keep-alive\r\n\r\n"), |
| 23193 | }; |
| 23194 | const MockRead kPostAuthReads[] = { |
| 23195 | MockRead(ASYNC, 1, |
| 23196 | "HTTP/1.1 200 OK\r\n" |
| 23197 | "Connection: keep-alive\r\n" |
| 23198 | "Content-Length: 9\r\n\r\n" |
| 23199 | "post-auth"), |
| 23200 | }; |
| 23201 | SequencedSocketData data_post_auth(kPostAuthReads, kPostAuthWrites); |
| 23202 | SSLSocketDataProvider ssl_post_auth(ASYNC, OK); |
| 23203 | ssl_post_auth.expected_send_client_cert = true; |
| 23204 | ssl_post_auth.expected_client_cert = identity->certificate(); |
| 23205 | session_deps_.socket_factory->AddSocketDataProvider(&data_post_auth); |
| 23206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_post_auth); |
| 23207 | |
| 23208 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 23209 | |
| 23210 | // Start the two long-lived requests. |
| 23211 | TestCompletionCallback callback_long_lived; |
| 23212 | auto trans_long_lived = |
| 23213 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23214 | int rv = trans_long_lived->Start( |
| 23215 | &request_long_lived, callback_long_lived.callback(), NetLogWithSource()); |
| 23216 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 23217 | data_long_lived.RunUntilPaused(); |
| 23218 | |
| 23219 | TestCompletionCallback callback_long_lived_bar; |
| 23220 | auto trans_long_lived_bar = |
| 23221 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23222 | rv = trans_long_lived_bar->Start(&request_long_lived_bar, |
| 23223 | callback_long_lived_bar.callback(), |
| 23224 | NetLogWithSource()); |
| 23225 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 23226 | data_bar.RunUntilPaused(); |
| 23227 | |
| 23228 | // Request /auth. This gives a client certificate challenge. |
| 23229 | TestCompletionCallback callback_auth; |
| 23230 | auto trans_auth = |
| 23231 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23232 | rv = trans_auth->Start(&request_auth, callback_auth.callback(), |
| 23233 | NetLogWithSource()); |
| 23234 | EXPECT_THAT(callback_auth.GetResult(rv), |
| 23235 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 23236 | |
| 23237 | // Make an unauthenticated request. This completes. |
| 23238 | TestCompletionCallback callback_unauth; |
| 23239 | auto trans_unauth = |
| 23240 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23241 | rv = trans_unauth->Start(&request_unauth, callback_unauth.callback(), |
| 23242 | NetLogWithSource()); |
| 23243 | EXPECT_THAT(callback_unauth.GetResult(rv), IsOk()); |
| 23244 | std::string response_unauth; |
| 23245 | EXPECT_THAT(ReadTransaction(trans_unauth.get(), &response_unauth), IsOk()); |
| 23246 | EXPECT_EQ("unauth", response_unauth); |
| 23247 | trans_unauth.reset(); |
| 23248 | |
| 23249 | // Complete the authenticated request. |
| 23250 | rv = trans_auth->RestartWithCertificate(identity->certificate(), |
| 23251 | identity->ssl_private_key(), |
| 23252 | callback_auth.callback()); |
| 23253 | EXPECT_THAT(callback_auth.GetResult(rv), IsOk()); |
| 23254 | std::string response_auth; |
| 23255 | EXPECT_THAT(ReadTransaction(trans_auth.get(), &response_auth), IsOk()); |
| 23256 | EXPECT_EQ("auth", response_auth); |
| 23257 | trans_auth.reset(); |
| 23258 | |
| 23259 | // Complete the long-lived requests. |
| 23260 | data_long_lived.Resume(); |
| 23261 | EXPECT_THAT(callback_long_lived.GetResult(ERR_IO_PENDING), IsOk()); |
| 23262 | std::string response_long_lived; |
| 23263 | EXPECT_THAT(ReadTransaction(trans_long_lived.get(), &response_long_lived), |
| 23264 | IsOk()); |
| 23265 | EXPECT_EQ("long-lived", response_long_lived); |
| 23266 | trans_long_lived.reset(); |
| 23267 | |
| 23268 | data_bar.Resume(); |
| 23269 | EXPECT_THAT(callback_long_lived_bar.GetResult(ERR_IO_PENDING), IsOk()); |
| 23270 | std::string response_long_lived_bar; |
| 23271 | EXPECT_THAT( |
| 23272 | ReadTransaction(trans_long_lived_bar.get(), &response_long_lived_bar), |
| 23273 | IsOk()); |
| 23274 | EXPECT_EQ("long-lived", response_long_lived_bar); |
| 23275 | trans_long_lived_bar.reset(); |
| 23276 | |
| 23277 | // Run the post-authentication requests. |
| 23278 | TestCompletionCallback callback_post_auth; |
| 23279 | auto trans_post_auth = |
| 23280 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23281 | rv = trans_post_auth->Start(&request_post_auth, callback_post_auth.callback(), |
| 23282 | NetLogWithSource()); |
| 23283 | EXPECT_THAT(callback_post_auth.GetResult(rv), IsOk()); |
| 23284 | std::string response_post_auth; |
| 23285 | EXPECT_THAT(ReadTransaction(trans_post_auth.get(), &response_post_auth), |
| 23286 | IsOk()); |
| 23287 | EXPECT_EQ("post-auth", response_post_auth); |
| 23288 | trans_post_auth.reset(); |
| 23289 | |
| 23290 | TestCompletionCallback callback_post_auth_bar; |
| 23291 | auto trans_post_auth_bar = |
| 23292 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 23293 | rv = trans_post_auth_bar->Start(&request_post_auth_bar, |
| 23294 | callback_post_auth_bar.callback(), |
| 23295 | NetLogWithSource()); |
| 23296 | EXPECT_THAT(callback_post_auth_bar.GetResult(rv), IsOk()); |
| 23297 | std::string response_post_auth_bar; |
| 23298 | EXPECT_THAT( |
| 23299 | ReadTransaction(trans_post_auth_bar.get(), &response_post_auth_bar), |
| 23300 | IsOk()); |
| 23301 | EXPECT_EQ("post-auth", response_post_auth_bar); |
| 23302 | trans_post_auth_bar.reset(); |
| 23303 | } |
| 23304 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 23305 | } // namespace net |